Created
June 8, 2013 18:17
-
-
Save rod-dot-codes/5736100 to your computer and use it in GitHub Desktop.
This returns your current IP.
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/python | |
import mechanize | |
class GetMyIP(): | |
def __init__(self): | |
br = mechanize.Browser() | |
br.set_handle_equiv(True) | |
#br.set_handle_gzip(True) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
self.br = br | |
def get_my_ip(self): | |
result = self.br.open("http://ifconfig.me/all.json") | |
result = result.read() | |
import simplejson as json | |
json_file = json.loads(result) | |
return json_file["ip_addr"] | |
if __name__ == "__main__": | |
getIP = GetMyIP() | |
print getIP.get_my_ip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment