Clean way to get one's network IP address?

John J. Lee jjl at pobox.com
Thu Nov 22 16:50:06 EST 2007


Gilles Ganault <nospam at nospam.com> writes:

> I need to get the local computer's IP address, ie. what's displayed
> when running "ifconfig" in Linux:
>
> # ifconfig
> eth0      Link encap:Ethernet  HWaddr 00:15:58:A1:D5:6F  
>           inet addr:192.168.0.79  Bcast:192.168.0.255
> Mask:255.255.255.0
>
> I know about socket.gethostbyname, but this relies on what's in
> /etc/hosts, and I'd rather have a more independent solution.
>
> What would be a good way to do this?

Here's one way:

http://www.google.com/codesearch?hl=en&q=+class+IfConfig+show:qb29leCQ7IU:wjsmn477sKk:0dc7V3lzLaI&sa=N&cd=1&ct=rc&cs_p=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-4-stable/All/linkchecker-4.5.tgz&cs_f=lib/python2.4/site-packages/linkcheck/dns/ifconfig.py#first


John



More information about the Python-list mailing list