codecraig wrote:
hi,
   how can i use python to figure the ip address of the machine which
the python script is running on?  I dont mean like 127.0.0.1....but i
want the external IP address (such as ipconfig on windows displays).

any ideas??

THanks


To get the public IP (like when you're behind a wirless router, etc) you may try doing something like this:


import urllib
import re
import time

ip_search = re.compile ('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')

try:
    f = urllib.urlopen("http://www.ipchicken.com";)
    data = f.read()
    f.close()
    current_ip = ip_search.findall(data)
    if current_ip:
        print current_ip
        time.sleep(3)
except Exception:
    pass

HTH,

rbt
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to