- 設(shè)計(jì)蜂巢IP地址查詢接口:http://www./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./app/geoip.js
- 有道IP地址查詢接口:http://www.youdao.com/smartresult-xml/search.s
- 1616 IP地址查詢接口:http://w./chaxun/iptolocal.php
- 126 http://ip.ws.126.net/ipquery
- hao123 http://app.hao123.com/ipquery/getcity.php?rtype=2
設(shè)計(jì)蜂巢接口調(diào)用方法API請(qǐng)求地址 : http://www./api/ip/ip.php?參數(shù) 參數(shù)說(shuō)明: - IP : IP地址 可選
- format : 輸出格式 json 可選 默認(rèn)為JS
JSON調(diào)用示例: 請(qǐng)求地址:http://www./api/ip/ip.php?callback=jQuery17107324279078748077_1327024991339&format=json&_=1327024991363 { “ip”: “117.89.35.58″, “province”: “\u6c5f\u82cf”, “city”: “\u5357\u4eac” }
騰訊接口調(diào)用方法- <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>
該方法已經(jīng)不可用,,訪問(wèn)http://fw.qq.com/ipaddre顯示“The page you are looking for is temporarily unavailable.Please try again later.”,。騰訊對(duì)Referer做了判斷,雖然可以通過(guò)PHP偽造Referer,,但是實(shí)際測(cè)試中獲得的是服務(wù)器的IP地址而不是客戶端的IP地址。我們一起鄙視一下騰訊,。新浪接口調(diào)用方法- <script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"></script>
- <script type="text/javascript">
- //format參數(shù)設(shè)置返回格式 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"]+"市")//中國(guó),江蘇省,南京市
- </script>
搜狐接口調(diào)用方法- <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
- <script type="text/javascript">
- //默認(rèn)為GBK可通過(guò)ie參數(shù)設(shè)置編碼
- console.log(returnCitySN["cip"]+','+returnCitySN["cname"])//117.89.35.98,江蘇省南京市
- </script>
谷歌接口調(diào)用方法據(jù)說(shuō)是谷歌的,,不知道是不是真的。 - <script src="http://j./app/geoip.js"></script>
- <script type="text/javascript">
- console.log(geoip_country_name()+','+geoip_region_name()+','+geoip_city())//China,Jiangsu,Nanjing
- </script>
有道接口調(diào)用方法調(diào)用接口示例:http://www.youdao.com/smartresult-xml/search.s?type=ip&q=123.233.157.9 返回XML數(shù)據(jù) <?xml version="1.0" encoding="gbk"?> <smartresult> <product type="ip"> <ip>123.233.157.9</ip> <location>山東省濟(jì)南市 網(wǎng)通</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數(shù)據(jù) fYodaoCallBack(1, {‘product’:'ip’,'ip’:’192.168.1.1′,’location’:'局域網(wǎng) 對(duì)方和您在同一內(nèi)部網(wǎng)’} , ”);
單獨(dú)寫(xiě)一個(gè)新浪的
- // 新浪根據(jù)ip獲取地址
- var province = '' ;
- var city = '' ;
- jQuery.getScript("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js",function(){
- province = remote_ip_info["province"];
- city = remote_ip_info["city"];
-
- }) ;
在加個(gè)方法返回當(dāng)前省份的省會(huì)或者直轄市名稱 //判斷當(dāng)前城市的省會(huì) function SwitchCity(province) { var city = ""; if (province.indexOf("河北") != -1) { city = "石家莊"; return city; } else if (province.indexOf("山西") != -1) { city = "太原"; return city; } else if (province.indexOf("遼寧") != -1) { city = "沈陽(yáng)"; return city; } else if (province.indexOf("吉林") != -1) { city = "長(zhǎng)春"; return city; } else if (province.indexOf("山西") != -1) { city = "太原"; return city; } else if (province.indexOf("黑龍江") != -1) { city = "哈爾濱"; return city; } else if (province.indexOf("江蘇") != -1) { city = "南京"; return city; } else if (province.indexOf("浙江") != -1) { city = "杭州"; return city; } else if (province.indexOf("福建") != -1) { city = "福州"; return city; } else if (province.indexOf("江西") != -1) { city = "南昌"; return city; } else if (province.indexOf("山東") != -1) { city = "濟(jì)南"; return city; } else if (province.indexOf("河南") != -1) { city = "鄭州"; return city; } else if (province.indexOf("廣東") != -1) { city = "廣州"; return city; } else if (province.indexOf("湖南") != -1) { city = "長(zhǎng)沙"; return city; } else if (province.indexOf("海南") != -1) { city = "???; return city; } else if (province.indexOf("四川") != -1) { city = "成都"; return city; } else if (province.indexOf("貴州") != -1) { city = "貴陽(yáng)"; return city; } else if (province.indexOf("云南") != -1) { city = "昆明"; return city; } else if (province.indexOf("陜西") != -1) { city = "西安"; return city; } else if (province.indexOf("臺(tái)灣") != -1) { city = "臺(tái)北"; return city; } else if (province.indexOf("內(nèi)蒙古") != -1) { city = "呼和浩特"; return city; } else if (province.indexOf("廣西") != -1) { city = "南寧"; return city; } else if (province.indexOf("西藏") != -1) { city = "拉薩"; return city; } else if (province.indexOf("寧夏") != -1) { city = "銀川"; return city; } else if (province.indexOf("新疆") != -1) { city = "烏魯木齊"; return city; } else if (province.indexOf("上海") != -1) { city = "上海"; return city; } else if (province.indexOf("重慶") != -1) { city = "重慶"; return city; } else if (province.indexOf("北京") != -1) { city = "北京"; return city; } else if (province.indexOf("天津") != -1) { city = "天津"; return city; } return city; }
|