Skip to content

Instantly share code, notes, and snippets.

@amites
Created May 25, 2012 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amites/2786450 to your computer and use it in GitHub Desktop.
Save amites/2786450 to your computer and use it in GitHub Desktop.
find public ip using python (executable)
!#/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