how to get my internet ip address?

Donn Cave donn at u.washington.edu
Mon Jan 28 17:59:09 CET 2002


Quoth Gerhard Hring <gh_pythonlist at gmx.de>:
...
| Alas, it's not that simple :-( My FreeBSD gateway at home has two
| ethernet cards, and you'd have to check the default route to know which
| one is connected to the DSL router. And even then, the DSL router
| doesn't have a publicly routed IP address, but only an internal one in
| my ISP's network. 

My trick for this problem is to establish a connection to my primary
name service IP, service port 53 (just because it's a known and reasonably
reliable network service), and then get the address of my end of the
connection with the getsockname() method.

That way, I know I'm getting the same address I'll use with any similar
connection in the near future.  Bearing in mind that addresses vary not
only for network topology but also over time, if you're on something like
a serial IP link that releases and reassigns IPs on timeouts.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list