2011-02-05 5 views
2

誰かがIP上でwhoisを実行し、そのIPから国コードを抽出した経験があったのでしょうか?どのapiがPHPでこれを行う最もクリーンな方法だろうかと思います。IPから国コードを抽出するための優れたphp API?

+1

、あなたはwhoisではなくジオロケーションを探しています。しかし役に立つ質問+1 – Endophage

+0

https://api.ipdata.co/8.8.8.8 8.8.8.8を任意のipに置き換えます – Jonathan

答えて

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

で入手できます。
関連する問題