IP to Country - IPv6

Adam picture Adam · Jan 30, 2012 · Viewed 7.7k times · Source

I've been using an IPv4 to country convertor successfully. eg: get IP of machine and compare to table to get country.

I'm updating this currently and with IPv6 around the corner I wanted to ask if there is a solution for converting IPv6 to country?

Note: preference for PHP and MySQL

thx

Answer

Ben Dowling picture Ben Dowling · Aug 30, 2014

If you're OK with using a web service then my service http://ipinfo.io recently added IPv6 support:

$ curl http://ipinfo.io/2001:4860:4860::8888
{
  "ip": "2001:4860:4860::8888",
  "hostname": "No Hostname",
  "city": null,
  "region": null,
  "country": "US",
  "loc": "38.0000,-97.0000",
  "org": "AS15169 Google Inc."
}

You can either parse the JSON response to get the country, or add country to the URL:

$ curl http://ipinfo.io/2001:4860:4860::8888/country
US

See http://ipinfo.io/developers for more details.