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

Diez B. Roggisch deets at nospam.web.de
Tue Aug 5 18:59:57 EDT 2008


Timothy Grant schrieb:
> 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, 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.

Try scraping a service like http://www.meineip.de/

Diez



More information about the Python-list mailing list