Best way to get ip address
Darren Kirby
bulliver at badcomputer.no-ip.com
Thu Sep 9 21:07:44 EDT 2004
quoth the John Lenton:
> this is more convoluted, and depends on a third party, but I find it's
> the most reliable way to find out what you seem to be wanting:
>
> re.findall('[0-9.]+',
> urllib.urlopen('http://checkip.dyndns.org/').read())[-1]
>
> there are several apps out there that depend on checkip.dyndns.org,
> and it's a published service, so it shouldn't be changing too often.
>
> HTH.
This is funny. I just spent the last hour putting together this:
def getIpAddress():
command = "lynx -dump http://whatismyip.com | awk '/Your/ {print $4}'"
x = commands.getstatusoutput(command)
if x[0] != 0:
ip = '127.0.0.1'
else:
ip = x[1]
return ip
Same principle, but relies on a third party and two system commands. I think I
will re-write it to use urllib as in your example.
Thanks everyone for the help...I think I've got it now.
-d
--
Part of the problem since 1976
http://badcomputer.no-ip.com
Get my public key from
http://keyserver.linux.it/pks/lookup?op=index&search=bulliver
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20040909/3f51694b/attachment.sig>
More information about the Python-list
mailing list