Enumerating Network Adapters

Thomas Heller theller at python.net
Mon Aug 30 10:45:05 EDT 2004


Dave Brueck <dave at pythonapocrypha.com> writes:

> Olivier Parisy wrote:
> [snip]
>> But actually, a previously posted message suggests a portable way to get
>> the platform IPs. Citing John Abel :
>>  > socket.gethostbyaddr( socket.gethostname() ) will return all the
>>  > details that you need to know.  For example, the output of that
>>  > command on my machine is :
>>  >
>>  > ('hallows', [], ['101.101.101.102', '10.253.1.118'])
>> Are there some pitfalls I'm not aware of ?
>
> Doesn't seem to work right on Windows, for me at least:
>
>  >>> socket.gethostbyaddr(socket.gethostname())
> ('<my machine name>', [], ['169.254.0.100'])
>
> It returned the least useful of my 3 IP addresses - my loopback
> adapter - but didn't return my LAN and wireless IPs.

If anyone really needs it, I can post code for windows using ctypes to
collect ip-addresses and netmasks together with the name and description
of all network adapters.

Thomas



More information about the Python-list mailing list