I am looking for IP address to geocoding data sources and/or APIs. Open to any formats, and the main concern is the quality, depth, and freshness of the data.
There are three sources that may be helpful:
- The answer on Stack Overflow on how to Geocode an IP Address
- Free GEOIP has a RESTful API for this specific task
- The Google Map API
- A geolocation XML API from PInfoDB
-
1Interesting, but I don't think the Google Map API and IPInfoDB qualify as open data :-) – Nicolas Raoul May 26 '14 at 3:12
-
PInfoDB requires registration for use of the API, but for the same reasons many sites do in collecting metrics, rather than charging for the service. I included Google Map API only as a secondary component that may help @blunders to map the results of any earlier query. – Jeanne Holm May 26 '14 at 3:47
-
1They seem (but I am not 100% sure) to use data from lite.ip2location.com/databases . These databases come either with a commercial license or with a free license. The free license says
The LITE edition is an open-source version of database with limited accuracy & number of records compares to commercial release. It is free for personal or commercial use with attribution required
. So I was wrong, IPInfoDB seems to qualify as open data indeed :-) – Nicolas Raoul May 26 '14 at 3:57
(Just to add details to the second list item in Jeanne's answer)
freegeoip.net is a community-built IP geocoding platform.
Database files are downloaded automatically by the updatedb script from the blog.freegeoip.net domain and according to their blog the data actually comes from the Geolite databases which are disctributed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
In addition:
- The engine itself is open source
- There is even a free hosted API (with hourly limits)
For a project I use the GeoLite City download from MaxMind. The license is "Creative Commons Attribution-ShareAlike 3.0 Unported License."
This file is usually updated every month, so I have a script that checks if the file has been updated and only downloads/unzips if it has:
wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
I choose the binary file, and not the CSV, because there is a nice python library to load this data and then do the lookups: pygeoip. For thousands of IP addresses, I found this process much faster than sending each IP address to an external web API.
A python snippet to load the IP table and then do a lookup:
import pygeoip
gi = pygeoip.GeoIP('GeoLiteCity.dat')
print gi.record_by_addr('64.233.161.99')
provides a JSON output like this:
{'city': u'Mountain View', 'region_name': u'CA', 'area_code': 650, 'time_zone': 'America/Los_Angeles', 'dma_code': 807, 'metro_code': 'San Francisco, CA', 'country_code3': 'USA', 'latitude': 37.41919999999999, 'postal_code': u'94043', 'longitude': -122.0574, 'country_code': 'US', 'country_name': 'United States', 'continent': 'NA'}
Three more IP geolocation APIs/Datasets I can suggest:
www.ip2location.com - free version for non-commercial use
www.hostip.info - crowdsourced dataset and API
dev.maxmind.com/geoip/legacy/geolite/ - free IP geolocation dataset