Skip to content

Instantly share code, notes, and snippets.

@moshekaplan
Last active October 10, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moshekaplan/3711488 to your computer and use it in GitHub Desktop.
Save moshekaplan/3711488 to your computer and use it in GitHub Desktop.
Get Public IP
#! /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