Skip to content

Instantly share code, notes, and snippets.

@gnuget
Created June 16, 2009 19:57
Show Gist options
  • Save gnuget/130856 to your computer and use it in GitHub Desktop.
Save gnuget/130856 to your computer and use it in GitHub Desktop.
get your ip address using python
#!/usr/bin/env python
import re
import urllib2
class get_ip:
def __init__(self):
pass
def show_ip(self):
pattern = re.compile("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")
headers = {'User-Agent':'Firefox','Referer':'http://www.google.com'}
request = urllib2.Request('http://checkip.dyndns.org',{},headers)
response = urllib2.urlopen(request)
ip = pattern.findall(response.read())
print ip[0]
if __name__ == "__main__":
cosa = get_ip()
cosa.show_ip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment