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

Christian Heimes lists at
Wed Aug 6 01:09:19 CEST 2008

David York wrote:
> How do I find out my machine's IP address as visible to the outside world?
> Thanks a lot.

Most modern routers home routers support the IGD part of UPnP 
( You can 
use an UPnP client software to query the router for its WAN IP, 
connection state and upload / download speed. You may even be able to 
modify the port forwarding rules with UPnP. I suggest Miniupnpc, because 
it has nice Python bindungs.

Another option is You can register a new DDNS host, update 
it with a DDNS client and then query the IP with socket.gethostbyname(). 
Most modern routers have a builtin DDNS client, too.


More information about the Python-list mailing list