public
Created

find public ip using python (executable)

  • Download Gist
findIP.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
!#/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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.