Finding IP address of localhost via socket API (or other API)
timothy.grant at gmail.com
Wed Aug 6 00:48:26 CEST 2008
On Tue, Aug 5, 2008 at 2:50 PM, David York <davideyork at gmail.com> wrote:
> Does anybody know how to find the real IP address (e.g.: address visible to
> internet) of a machine via Python? In other words I have a machine with an
> IP address something like 192.168.1.5, an address given to me by a router.
> The router's address (and thus my machine's address) to the outside world is
> something realistic, 126.96.36.199 or whatever. How do I get that
> number? I've tried socket.getaddrinfo('localhost', None) but all I get is
> 127.0.0.1 as expected.
> How do I find out my machine's IP address as visible to the outside world?
> Thanks a lot.
I'm not sure what you are trying to accomplish. The machine I'm typing
this on has a 192.168.x.x number. The router that gave it to me also
has a 192.168.x.x number. However, I know that that is not the IP that
the world sees when my packets finally leave the building.
What if your machine has multiple interface cards in it?
What are you trying to accomplish?
tjg. [Timothy Grant]
More information about the Python-list