IP查詢介面地址庫及其簡單使用方法

來源:互聯網
上載者:User
這裡分享幾個目前能用的,大家各取所需吧。

一、淘寶IP地址庫

*. 網址:http://ip.taobao.com/

*. 請求介面(GET):http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址]

*. 返回資料格式:(json格式的)國家 、省(自治區或直轄市)、市(縣)、電訊廠商。例如:

{"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317","region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1","country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000","county_id":"-1","isp_id":"100017"}}

註:其中code的值的含義為,0:成功,1:失敗。

*.  淘寶IP介面使用樣本PHP版:

<?php$ip=get_ip_data();function get_ip_data(){$ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip());$ip = json_decode($ip);if($ip->code){return false;}$data = (array) $ip->data;print_r($data);//return $data;}//取用戶端 ipfunction get_client_ip(){if (isset($_SERVER['HTTP_CLIENT_IP']) and !empty($_SERVER['HTTP_CLIENT_IP'])){return $_SERVER['HTTP_CLIENT_IP'];}if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){return strtok($_SERVER['HTTP_X_FORWARDED_FOR'], ',');}if (isset($_SERVER['HTTP_PROXY_USER']) and !empty($_SERVER['HTTP_PROXY_USER'])){return $_SERVER['HTTP_PROXY_USER'];}if (isset($_SERVER['REMOTE_ADDR']) and !empty($_SERVER['REMOTE_ADDR'])){return $_SERVER['REMOTE_ADDR'];} else {return "0.0.0.0";}}?>

二、新浪IP地址查詢介面

*. 請求介面(GET):http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=[ip地址]

註:參數format可設定返回格式:js/json;參數ip可選查詢IP;

*.  返回格式如下:

var remote_ip_info = {"ret":1,"start":"125.40.0.0","end":"125.40.111.255","country":"\u4e2d\u56fd","province":"\u6cb3\u5357","city":"\u90d1\u5dde","district":"","isp":"\u8054\u901a","type":"","desc":""};

下面的執行個體用到了JQuery下的getScript()方法:

<div id="sina_ip_info"></div><script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script><script type="text/javascript">var uip = '8.8.8.8';$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='+uip, function(_result){var ipData = ""; //初始化儲存內容變數if (remote_ip_info.ret == '1'){ipData += "IP 詳細資料:<br>";ipData += "IP:" + uip + "<br>";ipData += "國家:" + remote_ip_info.country + "<br>";ipData += "省份:" + remote_ip_info.province + "<br>";ipData += "城市:" + remote_ip_info.city + "<br>";ipData += "區:" + remote_ip_info.district + "<br>";ipData += "ISP:" + remote_ip_info.isp + "<br>";ipData += "類型:" + remote_ip_info.type + "<br>";ipData += "其他:" + remote_ip_info.desc + "<br>";$("#sina_ip_info").html(ipData); //顯示處理後的資料} else {alert('錯誤', '沒有找到匹配的 IP 位址資訊!');}});</script>

三、搜狐IP地址查詢介面(預設編碼GBK)

*. 請求介面(GET):http://pv.sohu.com/cityjson?ie=utf-8

四、太平洋IP地址庫API介面

*. 請求介面(GET):http://whois.pconline.com.cn/?ip=[ip地址字串]

調用方法非常豐富,提供多種JS嵌入調用。



相關文章

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。