查詢IP地址資訊

來源:互聯網
上載者:User

原文連結:http://www.yovisun.me/sina-wangyi-ip-addr-api.html 
作者:YoviSun 

通過IP地址擷取對應的地區資訊通常有兩種方法:

1)自己寫程式,解析IP對應的地區資訊,需要資料庫。

2)根據第三方提供的API查詢擷取地區資訊。

第一種方法,參見文本《通過純真IP資料庫擷取IP地址對應的地區資訊》,這種方法的維護代價較高,而且對自己的伺服器有一定的壓力。

隨著技術的開放,第三方已經逐漸免費開放相應的API。經過測試,目前網易和新浪提供的較為穩定易用。

1)新浪IP地址查詢API介面

新浪的IP地址查詢介面:

http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=IP地址

測試案例:

http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=115.156.238.114

返回以下資訊:

  1. var remote_ip_info = {"ret":1,"start":"115.156.128.0","end":"115.156.255.255","country":"\u4e2d\u56fd","province":"\u6e56\u5317","city":"\u6b66\u6c49","district":"","isp":"\u6559\u80b2\u7f51","type":"\u5b66\u6821","desc":"\u534e\u4e2d\u79d1\u6280\u5927\u5b66\u4e1c\u6821\u533a"};  

文字經過utf-8編碼,分別對應不同的資訊。

可以通過javascript跨域直接調用,如(使用jquery):

  1. $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='+ip, function(_result){  
  2. if (remote_ip_info.ret == '1'){   
  3. alert('IP 詳細資料:', 'IP:'+ip+'<BR>國家:'+remote_ip_info.country+'<BR>省份:'+remote_ip_info.province+'<BR>城市:'+remote_ip_info.city+'<BR>區:'+remote_ip_info.district+'<BR>ISP:'+remote_ip_info.isp+'<BR>類型:'+remote_ip_info.type+'<BR>其他:'+remote_ip_info.desc);
      
  4. } else {   
  5. alert('錯誤', '沒有找到匹配的 IP 地址資訊!');   
  6. }  
2)網易有道IP地址API介面

查詢IP地址:

http://www.youdao.com/smartresult-xml/search.s?type=ip&q=IP地址

舉例:

http://www.youdao.com/smartresult-xml/search.s?type=ip&q=115.156.238.114

返回xml文本資訊:

  1. <?xml version="1.0" encoding="gbk"?>  
  2. <smartresult>  
  3. <product type="ip">  
  4. <ip>115.156.238.114</ip>  
  5. <location>湖北省武漢市 教育網</location>  
  6. </product>  
  7. </smartresult> 

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.