程序员的资源宝库

网站首页 > gitee 正文

新浪网易淘宝等IP地区信息查询开放API接口调用方法

sanyeah 2024-04-01 12:01:27 gitee 5 ℃ 0 评论

通过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>  

3)淘宝IP地址库API接口

1. 请求接口(GET):

http://ip.taobao.com/service/getIpInfo.php?ip=[ip地址字串]

2. 响应信息:

(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商

3. 返回数据格式:

{"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:失败。

访问限制:为了保障服务正常运行,每个用户的访问频率需小于10qps。
详细请参看API主页:http://ip.taobao.com/

4)太平洋IP地址库API接口

http://whois.pconline.com.cn/?ip=[ip地址字符串]

调用方法非常丰富,提供多种JS嵌入调用。

另外,还有Google,搜狐,腾讯等均提供相应接口,请参看相关资料,这里不再赘述。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表