问题
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
回答1:
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.
回答2:
Maxmind have support for IPv6 in their GeoIP Country database.
回答3:
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"
}⏎
来源:https://stackoverflow.com/questions/9060895/ip-to-country-ipv6