How to determine own IP

Thomas Wouters thomas at xs4all.net
Sun Feb 18 17:51:12 EST 2001


On Sun, Feb 18, 2001 at 11:21:44PM +0100, Michael Bauer wrote:

> I'm stuck with a kind of dumb problem. I'm implementing a project based on 
> a distributed, decentralised network. Communication between nodes is 
> established through xml-rpc.
> For a new host to gather some other members of the network, it sends out a 
> PING that is passed on through the net. Each host receiving the PING 
> returns a PONG. Since the PONG is not sent directly to the new host but 
> passed back through all hosts that passed on the PING, i need to store the 
> IP of the answering hosts inside the PONG package.
> 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.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list