Skip to content

Instantly share code, notes, and snippets.

@mwatts272
Last active December 17, 2015 18:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwatts272/5657250 to your computer and use it in GitHub Desktop.
Save mwatts272/5657250 to your computer and use it in GitHub Desktop.
An easy means of getting a Users Geographic Data based from their Internet Protocol Address. Please Note: Please only use your public IP Address, and not your routers self assigned IP Address.
#!/usr/bin/env python
"""
Retrieves Geographic Information (Location) of a specified IP Address
"""
import urllib
ipAddress = '50.57.97.17'
response = urllib.urlopen('http://www.geoplugin.net/json.gp?ip={0}' .format(ipAddress)).read()
"""
Result of str(response):
{
"geoplugin_request":"50.57.97.17",
"geoplugin_status":200,
"geoplugin_credit":"Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\\'http:\/\/www.maxmind.com\\'>http:\/\/www.maxmind.com<\/a>.",
"geoplugin_city":"San Antonio",
"geoplugin_region":"TX",
"geoplugin_areaCode":"210",
"geoplugin_dmaCode":"641",
"geoplugin_countryCode":"US",
"geoplugin_countryName":"United States",
"geoplugin_continentCode":"NA",
"geoplugin_latitude":"29.488899",
"geoplugin_longitude":"-98.398697",
"geoplugin_regionCode":"TX",
"geoplugin_regionName":"Texas",
"geoplugin_currencyCode":"USD",
"geoplugin_currencySymbol":"&#36;",
"geoplugin_currencySymbol_UTF8":"$",
"geoplugin_currencyConverter":1
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment