[性能测试]免费IP归属地查询接口汇总

Song2247 次浏览0个评论2019年07月22日

目前做一个项目,需要判断是国内还是国外IP,具体要求为接口稳定,速度快,免费,不异常。所以我整理了优质的接口供大家筛选。

一、淘宝API接口

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

ip参数中添加你要查询的ip,返回数据为json格式。包括国家地区运营商等数据。

{"code":0,"data":{"ip":"221.218.209.125","country":"中国","area":"","region":"北京","city":"北京","county":"XX","isp":"联通","country_id":"CN","area_id":"","region_id":"110000","city_id":"110100","county_id":"xx","isp_id":"100026"}}

测评结果:

查询到: 110 未查询到: 0 报错: 890 执行时间 314.29S

二、ip-api接口

可以调用http://ip-api.com/json/接口查询域名,默认为当前请求的IP

# 国际化英文显示
http://ip-api.com/json/
# 修改语言编码
http://ip-api.com/json/?lang=zh-CN
# 修改IP信息
http://ip-api.com/json/115.191.200.34?lang=zh-CN

返回数据为json格式。包括国家地区运营商等数据。

{"as":"AS6106 University of California, Riverside","city":"里弗赛德","country":"美国","countryCode":"US","isp":"University of California, Riverside","lat":33.9473,"lon":-117.4008,"org":"University of California, Riverside","query":"169.235.24.133","region":"CA","regionName":"加利福尼亚州","status":"success","timezone":"America/Los_Angeles","zip":"92521"}

测评结果:

三、搜狐IP地址查询

http://pv.sohu.com/cityjson
# 设置编码
http://pv.sohu.com/cityjson?ie=utf-8

当前只能查到区域信息,数据划分不是很明确:

var returnCitySN = {"cip": "221.218.209.125", "cid": "110108", "cname": "北京市海淀区"};

四、太平洋IP地址查询

太平洋IP地址库API接口为:

http://whois.pconline.com.cn/ipJson.jsp?ip=xxx.xxx.xxx.xxx&json=true

查询到数据如下:

{"ip":"221.218.209.125","pro":"北京市","proCode":"110000","city":"北京市","cityCode":"110000","region":"海淀区","regionCode":"110108","addr":"北京市海淀区 联通ADSL","regionNames":"","err":""}

太平洋IP查询的更多接入方式查看http://whois.pconline.com.cn/

测试结果:

查询到: 1000 未查询到: 0 报错: 0 执行时间 68.51S

测试结果

国内使用,

  • TOP1 太平洋IP为最优选择,国内准确率高,同时可以判断出国家
  • TOP2 淘宝API可用于国内查询,国外经常报错,速度不是太快
  • TOP3 ip-api接口,精确度高,但是速度不稳定,如果你对查询精度要求高,可以使用这个接口。
  • TOP4 搜狐IP没法测试

测试代码:

import requests
import random
import json
import time

i = 0
has = 0
nohas = 0
error = 0
start = time.time()
while i < 1000:
    i += 1
    ip = "115."+str(random.randint(1,199))+"."+str(random.randint(1,199))+"."+str(random.randint(1,199))
    try:
        response = requests.get(url="http://ip.taobao.com/service/getIpInfo.php",params={"ip":ip})
        texts = response.text
        infos = json.loads(texts)
        print(infos)
        country = infos["data"]["country"]
        if country:
            has += 1
        else:
            nohas += 1
    except:
        error += 1
end = time.time()
execution_time = end-start
print("查询到:",has,"未查询到:",nohas,"报错:",error,"执行时间",execution_time)

提交评论

请登录后评论

用户评论

    当前暂无评价,快来发表您的观点吧...

更多相关好文

    当前暂无更多相关好文推荐...