Home
> Uncategorized > Get External IP address in Python
Get External IP address in Python
Getting your External IP address requires a remote server to reply with your client ip. I used a one-liner PHP script with simply <?php echo $_SERVER[‘REMOTE_ADDR’]; ?> hosted at dananos.brinkster.net/ip.php
Then I used the following python script to request the IP from this URL, and then save the output to file.
import httplib
conn = httplib.HTTPConnection(“dananos.brinkster.net”)
conn.request(“GET”, “/ip.php”)
r1 = conn.getresponse()
data1 = r1.read()
f = open(‘tempfile.txt’, ‘w’)
f.write(data1)
f.close()
Bit of trial-and-error, but it works.
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback