我已经成功地使用了IPv4到国家/地区的转换器。例如:获取机器的IP并与表比较以获取国家。
我目前正在更新这一点,随着IPv6的临近,我想问一下是否有将IPv6转换为国家/地区的解决方案?
注意:首选PHP和MySQL
thx
如果您可以使用web服务,那么我的服务http://ipinfo.io最近添加的IPv6支持:
$ 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."
}
您可以解析JSON响应以获取国家/地区,也可以将国家/地区添加到URL:
$ curl http://ipinfo.io/2001:4860:4860::8888/country
US
请参阅http://ipinfo.io/developers了解更多详细信息。
Maxmind在其GeoIP国家/地区数据库中支持IPv6。
以下是https://ipdata.co
curl https://api.ipdata.co/2c0f:fd58:9:198::255e?api-key=test
这就产生了
{
"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"
}⏎
一个简单的方法是使用IP地理定位API,如我的服务:https://astroip.co它同时支持IPv4和IPv6。
呼叫:
https://api.astroip.co/2c0f:fd58:9:198::255e/?api_key=1725e47c-1486-4369-aaff-463cc9764026
退货:
{
"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"
}
您可以在上找到更多详细信息https://astroip.co/docs