[Twisted-Python] Can I get the interface's IP addr from where the datagram is received?
nkeric at gmail.com
Wed Jul 6 22:44:30 EDT 2005
2005/7/6, Tommi Virtanen <tv at twistedmatrix.com>:
> Assumption: you really need to know the address the packet was sent to,
> and not just "(one of) my IP address(es)".
Hi Tommi, thank you for your reply!
I'm having my server running on a machine which has two ethernet
interfaces, one has an intranet ip address like "192.168.3.4", another
one has a public internet ip address like "184.108.40.206".
I want my server to provide public services to the outside. One of its
function is to allocate some ports for the clients, once the
allocation has been done, the server has to send back an address pair
(ip:port) to the client.
I have written a method:
return socket.getaddrinfo(socket.gethostname(), None)
It worked properly several days ago and returned me the public address
(220.127.116.11) of that machine, however, yesterday, it kept returning
the intranet address (192.168.3.4) which was useless for the clients
on the internet. I can't figure out why...
I've tried to use the self.transport.getHost(), however, the result
was something like this: IPv4Address(UDP, '0.0.0.0', 6677). What's
wrong with this method?
Is it so hard to know the ip address from which the data my server received?
I'm very new to twisted and not a native english speaker, so please
bear with me :p
More information about the Twisted-Python