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 =
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?
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
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
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
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',
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
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
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.