Getting external IP address
sergio.correia at gmail.com
Tue Mar 6 20:40:37 CET 2007
The above suggestions seem nice, but I find this one easier:
ext_ip = urllib2.urlopen('http://whatismyip.org/').read()
The nice thing about the above code is that http://whatismyip.org/
only contains exactly what you want (the ip, nothing more, nothing
less), so no parsing is necessary
On 3/6/07, Cousin Stanley <cousinstanley at hotmail.com> wrote:
> > I have a PC behind a firewall, and I'm trying to programmatically
> > determine the IP address visible from outside the firewall.
> > ....
> Steven ....
> Following is another alternative that might at least
> be worth consideration ....
> I use the lynx command shown as a command-line alias
> under Debian linux ....
> >>> import os
> >>> pipe_in = os.popen( 'lynx --dump http://checkip.dyndns.org' )
> >>> ip_addr = pipe_in.readlines()
> >>> for this in ip_addr :
> ... print this
> Current IP Address: 188.8.131.52
> Stanley C. Kitching
> Human Being
> Phoenix, Arizona
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
> ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
More information about the Python-list