Last active
October 10, 2015 15:27
-
-
Save moshekaplan/3711488 to your computer and use it in GitHub Desktop.
Get Public IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
Includes a function for retrieving a public IP in a simple, programmatic fashion. | |
NOTE: Does not use HTTPS! | |
""" | |
import urllib2 | |
def get_public_ip(): | |
"""Retrieve the external IP address. | |
This is done by contacting whatismyip in a programmatic fashion. | |
""" | |
URL = "http://moshekaplan.com/cgi-bin/ip.py" | |
f = urllib2.urlopen(URL) | |
ip = f.read() | |
return ip | |
if __name__ == '__main__': | |
print get_public_ip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment