GeoIP的Web服务

Jus*_*tin 2 geoip

是否有可靠的 Web服务提供API来将IP地址转换为某个位置,即city, region, country.愿意支付,但需要坚实可靠的东西.

Ben*_*ing 7

我的服务http://ipinfo.io包括位置信息,主机名,网络所有者和其他一些细节:

$ curl ipinfo.io/8.8.8.8
{
  "ip": "8.8.8.8",
  "hostname": "google-public-dns-a.google.com",
  "loc": "37.385999999999996,-122.0838",
  "org": "AS15169 Google Inc.",
  "city": "Mountain View",
  "region": "CA",
  "country": "US",
  "phone": 650
}
Run Code Online (Sandbox Code Playgroud)

这是一个PHP示例:

$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
echo $details->city; // -> "Mountain View"
Run Code Online (Sandbox Code Playgroud)