Enumerating Network Adapters

Dave Brueck dave at pythonapocrypha.com
Mon Aug 30 10:26:31 EDT 2004


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.

-Dave



More information about the Python-list mailing list