Geographical API for getting location data from IP addresses
When I was designing a website for a map in Warcraft III Custom Hero Wars, here I decided I wanted to log information about people who downloaded the map to give the site a sense of community.
Once I had logging to a database the next logical step was visualizing this with a series of graphs of users from around the world and the frequency of their downloads. I found code to store most details, browser type, IP address, Operating System. What I wanted though was more detail on location, I had the IP address surely I thought I could get some sort of location from that.
Well it turns out you can't. Not without dishing out cash for location services. Anyway after a large amount of trolling though outdated broken posts about various solutions here there and everywhere I found an old site offering a database of locations to IP addresses and some API's for accessing it from Maxmind.com. It seemed ideal unfortunately it has to be hosted and none of the API's provided seemed to work anyway.
I kept searching and trying different things to get it to work I ended up finding a few examples from early 2005 and so until I eventually got together a working API that actually did most of the work for me. It isn't perfect as the database doesn't contain every IP address needed but it did do a fairly comprehensive and accurate job when it did have data.
It was what I'd needed for my logging so I implemented it and put it up on my home server and hooked into it from the Custom Hero Wars site and its now working well.
Once I found out how difficult it was to get this service running and noticed how many paid solutions were out there I thought it might be nice to open up my tool to other people so I designed a few safeguards so I could ban unsavory users and changed the interface to be more API like and have friendlier output added another method for returning information, did some testing and implemented IPv4 and IPv6 searching and made it go live.
Anyone who wants to use this service feel free but I ask that you tell me if you are going to continually use it more than five times in a day, any more than that and I might feel taken advantage of without prior notice, or that my server is getting to many hits :) and I might have to remove the offending persons access.
I've added what3words addresses calculated from the latitude and longitude returned from the service with a link to the relevant address on the what3words site, for anyone thats interested what3words has created a globe spanning address system in most if not all languages that resolves to three metre resolution anywhere on the planet with just three natural language words. Its a revolutionary addressing system that is far superior to current ones for ease of use for humans. read more about it here.
How to use the API
The API can return data in two ways XSL or XML the idea here is anyone visiting the site will want XSL so its nice and happily readable and anyone using it as an API for another service or data gathering will likely want xml so they can do their own parsing, error checking, presentation and can easily extract the values for their own purposes. I use the XML access myself for my Custom Hero Wars website and save the details to a MySQL database, then once an hour regenerate graphs showing downloads by city, country, state and other variables.
The API accepts formatting requests for data returns passed with the URL separated by ? and & symbols.
The following arguments are supported:
Both arguments are optional and are passed in the URL request to the page i.e..
or mode=anything else for XML. IP can be a IPv4 or IPv6 address i.e..
?ip=10.1.2.4 or ?ip=2607:f0d0:1002:51::4
?ip=10.1.2.4&mode=xsl or ?ip=2607:f0d0:1002:51::4&mode=xml
Remember any other mode then XSL will produce XML for now but to minimize issues in ongoing compatibility it is suggested you use the mode xml to retrieve xml results.
Incidentally the Globe icon is from http://www.utechworld.com/projects/spinning-earth/ and offered free to download and to use :)