Best way to get ip address
Nicolas Évrard
nicoe at altern.org
Thu Sep 9 15:57:17 EDT 2004
* Darren Kirby [21:07 09/09/04 CEST]:
>Hello list:
>
>I am writing a small app in python which tracks the kernel banner at
>kernel.org and downloads newer kernel version(s) (if there are any).
>
>I am using GeoIP to set the download to a local mirror if there is one. This
>is what I use to get the local IP address:
>
>ip = socket.gethostbyaddr(socket.gethostname())
># returns: ('hostname.domain', ['hostname'], ['192.168.0.2'])
>ip = str(ip[2])
># returns: "['192.168.0.2']"
>ip = ip[2:-2]
># returns: '192.168.0.2'
Why don't you use ip = ip[2][0] ?
--
(°> Nicolas Évrard
/ ) Liège - Belgique
^^
More information about the Python-list
mailing list