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

Christian Heimes lists at cheimes.de
Tue Aug 5 19:09:19 EDT 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 
(http://en.wikipedia.org/wiki/Internet_Gateway_Device_Protocol). 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 dyndns.org. 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.

Christian




More information about the Python-list mailing list