根據IP查詢所在城市介面(查詢使用者所在城市)
阿新 • • 發佈:2019-01-07
轉自:https://blog.csdn.net/liona_koukou/article/details/75646313
最近專案有用到定位使用者客戶端開啟頁面時所在的城市的需求,找到如下介面,做個記錄
文章為轉載
- 設計蜂巢IP地址查詢介面:http://www.hujuntao.com/api/ip/ip.php
- 騰訊IP地址查詢介面:http://fw.qq.com/ipaddress
- 新浪IP地址查詢介面:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
- 搜狐IP地址查詢介面:http://pv.sohu.com/cityjson
- 谷歌IP地址查詢介面:http://j.maxmind.com/app/geoip.js
- 有道IP地址查詢介面:http://www.youdao.com/smartresult-xml/search.s
- 1616 IP地址查詢介面:http://w.1616.net/chaxun/iptolocal.php
- 126 http://ip.ws.126.net/ipquery
- hao123 http://app.hao123.com/ipquery/getcity.php?rtype=2
設計蜂巢介面呼叫方法
API請求地址 : http://www.hujuntao.com/api/ip/ip.php?引數
引數說明:
- IP : IP地址 可選
- format : 輸出格式 json 可選 預設為JS
JSON呼叫示例:
請求地址:http://www.hujuntao.com/api/ip/ip.php?callback=jQuery17107324279078748077_1327024991339&format=json&_=1327024991363
{"ip":"117.89.35.58","province":"\u6c5f\u82cf","city":"\u5357\u4eac"}
騰訊介面呼叫方法
<script src="http://fw.qq.com/ipaddress"></script> <script type="text/javascript"> //反回格式如下://var IPData = new Array("117.89.35.98","","江蘇省","南京市"); console.log(IPData[0]+','+IPData[2]+','+IPData[3]);//117.89.35.98,江蘇省,南京市 </script>
該方法已經不可用,訪問http://fw.qq.com/ipaddre顯示“The page you are looking for is temporarily unavailable.
Please try again later.”。騰訊對Referer做了判斷,雖然可以通過PHP偽造Referer,但是實際測試中獲得的是伺服器的IP地址而不是客戶端的IP地址。我們一起鄙視一下騰訊。╭∩╮(︶︿︶)╭∩╮
新浪介面呼叫方法
<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.phpformat=js"></script> <script type="text/javascript"> //format引數設定返回格式 js/json // ip 要查詢IP 可選 // 反回格式如下: // var remote_ip_info = {"ret":1,"start":"117.89.35.0","end":"117.89.35.255","country":"\u4e2d\u56fd","province":"\u6c5f\u82cf","city":"\u5357\u4eac","district":"\u767d\u4e0b","isp":"\u7535\u4fe1","type":"","desc":""}; console.log(remote_ip_info["country"]+','+remote_ip_info["province"]+"省"+','+remote_ip_info["city"]+"市");//中國,江蘇省,南京市 </script>
搜狐介面呼叫方法
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script> <script type="text/javascript"> //預設為GBK可通過ie引數設定編碼 console.log(returnCitySN["cip"]+','+returnCitySN["cname"])//117.89.35.98,江蘇省南京市 </script>
谷歌介面呼叫方法
據說是谷歌的,不知道是不是真的。
<script src="http://j.maxmind.com/app/geoip.js"></script> <script type="text/javascript"> console.log(geoip_country_name()+','+geoip_region_name()+','+geoip_city())//China,Jiangsu,Nanjing </script>
有道介面呼叫方法
呼叫介面示例:http://www.youdao.com/smartresult-xml/search.s?type=ip&q=123.233.157.9
返回XML資料
<?xml version="1.0" encoding="gbk"?> <smartresult> <product type="ip"> <ip>123.233.157.9</ip> <location>山東省濟南市 網通</location> </product> </smartresult>
或者
http://www.youdao.com/smartresult-xml/search.s?jsFlag=true&keyfrom=163.com&event=fYodaoCallBack&type=ip&q=192.168.1.1
返回JSON資料
fYodaoCallBack(1, {"product":"ip","ip":"192.168.1.1","location":"區域網 對方和您在同一內部網"});