Here is a simple python 2.7 snippet for finding the current external IP address.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import httplib
import string
conn = httplib.HTTPConnection("checkip.dyndns.org", 80)
conn.request("GET","/index.html")
res = conn.getresponse()
conn.close()
if res.status == 200:
response = res.read()
else:
print 'Error connecting to the server!! Check your internet connection'
exit()
startstr = string.find(response,': ')+2
endstr = string.find(response,'</b')
print response[startstr:endstr]
|