Re: Getting external IP address

2007-03-06 Thread Steven D'Aprano
On Mon, 05 Mar 2007 09:02:44 +, Duncan Booth wrote: Try running it interactively and looking at the data you receive: conn = HTTPConnection('xml.showmyip.com') conn.request('GET', '/') resp = conn.getresponse() print resp httplib.HTTPResponse instance at 0x00C58350 data =

Re: Getting external IP address

2007-03-06 Thread Sion Arrowsmith
Steven D'Aprano [EMAIL PROTECTED] wrote: I have a PC behind a firewall, and I'm trying to programmatically determine the IP address visible from outside the firewall. [ ... ] Can anyone help me fix that code snippet, or suggest another (better) way to get the externally visible IP address?

Re: Getting external IP address

2007-03-06 Thread Cousin Stanley
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

Re: Getting external IP address

2007-03-06 Thread Sergio Correia
The above suggestions seem nice, but I find this one easier: import urllib2 ext_ip = urllib2.urlopen('http://whatismyip.org/').read() print ext_ip 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

Re: Getting external IP address

2007-03-06 Thread Steven D'Aprano
On Tue, 06 Mar 2007 14:40:37 -0500, Sergio Correia wrote: The above suggestions seem nice, but I find this one easier: [snip] Thanks to everybody who replied, that's great. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Getting external IP address

2007-03-05 Thread Steven D'Aprano
I have a PC behind a firewall, and I'm trying to programmatically determine the IP address visible from outside the firewall. If I do this: import socket socket.gethostbyname(socket.gethostname()) '127.0.0.1' socket.gethostbyname_ex(socket.gethostname()) ('localhost.localdomain',

Re: Getting external IP address

2007-03-05 Thread Duncan Booth
Steven D'Aprano [EMAIL PROTECTED] wrote: from httplib import HTTPConnection from xml.dom.ext.reader.Sax import FromXmlStream conn = HTTPConnection('xml.showmyip.com') conn.request('GET', '/') doc = FromXmlStream(conn.getresponse()) print doc.getElementsByTagName('ip')[0].firstChild.data

Re: Getting external IP address

2007-03-05 Thread Paul Rubin
Duncan Booth [EMAIL PROTECTED] writes: If you try connecting to 'www.showmyip.com' and requesting '/xml/' it should work. If the firewall is really obnoxious, it can bounce consecutive queries around between multiple originating IP addresses. That is uncommon but it's been done from time to

Re: Getting external IP address

2007-03-05 Thread Duncan Booth
Paul Rubin http://[EMAIL PROTECTED] wrote: Duncan Booth [EMAIL PROTECTED] writes: If you try connecting to 'www.showmyip.com' and requesting '/xml/' it should work. If the firewall is really obnoxious, it can bounce consecutive queries around between multiple originating IP addresses.