tags:

views:

1627

answers:

11
+16  Q: 

IP to Country?

Does anyone know of a simple way to retrieve the country for a given IP Address? Preferably in ISO_3166-1 format?

+7  A: 

Here's a nice free service with a public API: http://www.hostip.info/use.html

Mark Harrison
+15  A: 

A lot of people (including my company) seem to use MaxMind GeoIP.

They have a free version GeoLite which is not as accurate as the paid version, but if you're just after something simple, it may be good enough.

Orion Edwards
+3  A: 

I don't know how accurate that hostip.info site is. I just visted that site, and it reported that my country is Canada. I'm in the US and the ISP that my office uses only operates from the US. It does allow you to correct it's guess, but if you are using this service to track web site vistors by country, you'll have no way of knowing if the data is correct. Of course, I'm just one data point. I downloaded the GeoLite Country database, which is just a .csv file, and my IP address was correctly identified as US.

Another benefit of the MaxMind product line (paid or free) is that you have the data, you don't incur the performance hit of making a web service call to another system.

Chris Miller
A: 

hostip.info put me in a suburb of my city.

Zack Peterson
A: 

hostip.info told me this:

alt text

Edo
To quote the website: "Hostip.info is a community-based project to geolocate IP addresses, making the database freely available (see below) but it needs you to put in your city to make it work."
Milan Babuškov
+1  A: 

@Edo, so you clicked on the "Make a correction" link and gave them a clue, right? If you tell them, they'll be able to help other users in your area.

Jon Galloway
A: 

@Jon Galloway
I ment to do it but almost forgot, thanks :)

Edo
+6  A: 

There are two approaches: using an Internet service and using some kind of local list (perhaps wrapped in a library). What you want will depend on what you are building.

For services:

For lists:

Warren Blanchet
One of the most useful answers in general that I have seen in SO. Thank you!
ΤΖΩΤΖΙΟΥ
A: 

The most accurate is Digital Elements NetAcuity...not free but you get what you pay for most of the time....Digital Element

CSharpAtl
+1  A: 

ipinfodb provide a free database and API for ip to country and vice versa. They use free data from MaxMind. The data got updated every month, and it's a great free alternative with decent accuracy.

Donny Kurnia
Way better than maintaining your own database. Just tested it on a really obscure place (Uthai Thani, Thailand) and it was spot on. Great find, thanks!
JannieT
A: 

google's clientlocation returns (my example)

latlng = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
location = "IP location: " + getFormattedLocation();
document.getElementById("location").innerHTML = location;
LarsOn