Skip to content

Instantly share code, notes, and snippets.

@iordic
Created October 10, 2016 23:40
Show Gist options
  • Save iordic/3e54863fd4a99778a489b740747ece5b to your computer and use it in GitHub Desktop.
Save iordic/3e54863fd4a99778a489b740747ece5b to your computer and use it in GitHub Desktop.
import urllib
def extract_public_ip():
sock = urllib.urlopen('http://checkip.dyndns.com/')
public_ip = sock.read()
sock.close()
public_ip = public_ip.split(': ')[-1]
public_ip = public_ip.split('</body>')[0]
return public_ip
print 'Your public IP is: ' + extract_public_ip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment