2011-02-05 37 views
2

我想知道有沒有人在IP上做whois並從該IP提取國家代碼有任何經驗?想知道什麼是api會是用php做這個最簡單的方法。良好的PHP API從IP提取國家代碼?

+1

重新標記,您正在尋找地理位置,而不是whois。雖然如此,有用的問題+1 – Endophage 2011-02-05 00:35:36

回答

1

你可以用我的服務,http://ipinfo.io API此:

假設你希望所有的細節,你可以使用PHP的json_decode解析響應:也支持

function ip_details($ip) { 
    $json = file_get_contents("http://ipinfo.io/{$ip}"); 
    $details = json_decode($json); 
    return $details; 
} 

$details = ip_details("8.8.8.8"); 

echo $details->city;  // => Mountain View 
echo $details->country; // => US 
echo $details->org;  // => AS15169 Google Inc. 
echo $details->hostname; // => google-public-dns-a.google.com 

JSONP,所以你可以從JavaScript調用的API:

$.get("http://ipinfo.io", function(response) { 
    console.log(response.city); 
}, "jsonp"); 

更多詳細信息可在http://ipinfo.io/developers