Created
May 25, 2012 07:44
-
-
Save amites/2786450 to your computer and use it in GitHub Desktop.
find public ip using python (executable)
This file contains 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 | |
# simple python script to return your public IP address using whatismyip.com | |
# if executed from command line will display IP | |
def findIP(): | |
''' | |
Returns your IP address. Includes setting the header to match the request | |
see http://www.whatismyip.com/faq/automation.asp | |
''' | |
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0)' \ | |
+ ' Gecko/20100101 Firefox/12.0' } | |
return urllib2.urlopen( | |
urllib2.Request( | |
"http://automation.whatismyip.com/n09230945.asp", | |
None, headers ) | |
).read() | |
if __name__=="__main__": | |
print findIP() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment