IP to Country - IPv6 [closed]
Asked Answered
L

4

9

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

Lanoralanose answered 30/1, 2012 at 7:59 Comment(4)
Be aware that all geo-ip databases are approximations, and the quality of the IPv6 data is sadly still much worse than the quality of the IPv4 data.Bienne
I posted a very similar question a little before yours. I now answered it with the answer I found. Here's the link: #8404857Optimist
Maxmind claims to be 99,8% accurate when it comes to their geo-city database. Even if that is not true I think you should still be okay if you just want to get the country code. You can download free versions of the geoip databases or paid versions. You need to purchase updates to keep the tables up to date. I'm currently testing the ipv6 database for the same reason. If it turns out unusable I'll let you know.Vulcanize
IP2Location Lite database supports IPv6 as well. lite.ip2location.comArmstrong
C
9

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.

Casuistry answered 30/8, 2014 at 15:59 Comment(0)
A
4

Here's an example with https://ipdata.co

curl https://api.ipdata.co/2c0f:fd58:9:198::255e?api-key=test

Which gives

{
    "ip": "2c0f:fd58:9:198::255e",
    "city": "",
    "region": "",
    "country_name": "South Africa",
    "country_code": "ZA",
    "continent_name": "Africa",
    "continent_code": "AF",
    "latitude": -29.0,
    "longitude": 24.0,
    "asn": "AS20940",
    "organisation": "Akamai International B.V.",
    "postal": "",
    "currency": "ZAR",
    "currency_symbol": "R",
    "calling_code": "27",
    "flag": "https://ipdata.co/flags/za.png",
    "time_zone": "Africa/Johannesburg"
}⏎ 
Albuminate answered 6/11, 2017 at 17:8 Comment(0)
F
3

Maxmind have support for IPv6 in their GeoIP Country database.

Flittermouse answered 30/1, 2012 at 8:3 Comment(0)
E
0

An easy way is to use an IP Geolocation API like my service: https://astroip.co which supports both IPv4 and IPv6.

Calling:

https://api.astroip.co/2c0f:fd58:9:198::255e/?api_key=1725e47c-1486-4369-aaff-463cc9764026

Returns:

{
  "status_code": 200,
  "geo": {
    "is_metric": true,
    "is_eu": false,
    "longitude": 24,
    "latitude": -29,
    "country_geo_id": 953987,
    "zip_code": null,
    "city": null,
    "region_code": null,
    "region_name": null,
    "continent_code": "AF",
    "continent_name": "Africa",
    "capital": "Pretoria",
    "country_name": "South Africa",
    "country_code": "ZA"
  },
  "asn": {
    "route": "2c0f:fd58::/32",
    "name": "Vox-Telecom",
    "type": "isp",
    "domain": "voxtelecom.co.za",
    "organization": "Vox-Telecom",
    "asn": "AS11845"
  },
  "currency": {
    "native_name": "Suid-Afrikaanse rand",
    "code": "ZAR",
    "name": "South African Rand",
    "symbol": "R"
  },
  "timezone": {
    "is_dst": false,
    "gmt_offset": 7200,
    "date_time": "2020-11-23T22:59:29+02:00",
    "microsoft_name": "South Africa Standard Time",
    "iana_name": "Africa/Johannesburg"
  },
  "security": {
    "is_crawler": false,
    "is_proxy": false,
    "is_tor": false,
    "tor_insights": null,
    "proxy_insights": null,
    "crawler_insights": null
  },
  "crypto": null,
  "user_agent": null,
  "error": null,
  "ip_type": "ipv6",
  "ip": "2c0f:fd58:9:198::255e"
}

You can find more details on https://astroip.co/docs

Eleemosynary answered 23/11, 2020 at 21:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.