Created
June 16, 2009 19:57
-
-
Save gnuget/130856 to your computer and use it in GitHub Desktop.
get your ip address using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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