How to determine own IP

Michael Bauer Mike_B at
Sun Feb 18 18:21:09 EST 2001

Thomas Wouters wrote:

> On Sun, Feb 18, 2001 at 11:21:44PM +0100, Michael Bauer wrote:
>> Now, to the real problem :-)
>> If a host has more than one network adapter, how do i know which IP
>> should
>> i put inside  the PONG package?
>> Specifically, when dealing with dial-up users who are also connected to a
>> LAN, gethostbyname(gethostname()) always returns their internal adress.
> And don't forget multi-homed machines (multiple network
> cards/ip-addresses) and NAT/IP-Masquerading. You can't always trust what a
> machine thinks is its own ipaddress.
>> Any ideas?
> Have a 'WHOAMI' command/function/packet that's answered by the directly
> connected node(s). If you want highly-connected nodes, consider treating
> each node's response as unique for that node (so you can work both
> 'inside' and 'outside' a masqueraded network) and always use it for
> communication that came through the node.


Sometimes when you think something is really hard to solve, it turns out to 
be quite obvious ;-)

Thank you, Mike


More information about the Python-list mailing list