ifconfig in python

Ned Deily nad at acm.org
Tue Jan 20 03:48:45 CET 2009

In article 
<e1a84d570901191634u27e6b5d7h2f05a698213f6173 at mail.gmail.com>,
 "James Mills" <prologic at shortcircuit.net.au> wrote:

> On Tue, Jan 20, 2009 at 10:28 AM, Nehemiah Dacres <vivacarlie at gmail.com> 
> wrote:
> > Is ther an easy way to get the resolved ip address of the machine a script
> > is running on? socket.gethostbyname(socket.gethostname) has only returned
> > the ip address of my loop back interface ... not very usefull.
> That's because your /etc/hosts resolves
> your hostname to :)
> And no I know of no "easy" way cross
> platform way. Perhaps parsing the output
> of ifconfig itself ?

Also, since the subject is on my brain at the moment, how to find "the 
address" is not the right question to ask.  These days most systems have 
multiple network interfaces (Ethernet, WiFi, dialup, et al) running 
multiple protocols, like IPv4 and IPv6.  In general, there is no *one* 
IP address of a machine; often there are many.  Ignoring that fact can 
lead to subtle bugs, like the one causing a urllib2 regression test 
failure that I've been squashing today!

 Ned Deily,
 nad at acm.org

More information about the Python-list mailing list