Finding IP address of localhost via socket API (or other API)

David York davideyork at gmail.com
Tue Aug 5 17:50:34 EDT 2008


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, 123.156.123.156 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.

   David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080805/1a0ab485/attachment.html>


More information about the Python-list mailing list