get the IP address of a host

P at draigBrady.com P at draigBrady.com
Thu Jan 6 08:56:04 EST 2005


J Berends wrote:
> def getipaddr(hostname='default'):
[snip]

> 
> It returns the IP address with which it connects to the world (not lo), 
> might be a pvt LAN address or an internet routed IP. Depend on where the 
> host is.
> 
> I hate the google trick actually, so any suggestions to something better 
> is always welcome.

Yes your IP is determined really by what you connect to.
So I did essentially the same as you.
For reference see getMyIPAddress() at the following:
http://www.pixelbeat.org/libs/PadSocket.c

Pádraig



More information about the Python-list mailing list