记录几个国内外获取 ip 信息的 API
国内 API
ip-api
国内外都可以
1 2 3
| http://ip-api.com/json
|
百度
百度首页获取 IP 信息的 api,比较准。对方官网:埃文科技
1 2 3 4 5 6 7 8 9 10 11
| # 获取IP详情 curl https://qifu-api.baidubce.com/ip/local/geo/v1/district
# 只获取IP https://www.ipplus360.com/getIP curl https://www.ipplus360.com/getIP
# 只获取地理位置 https://www.ipplus360.com/getLocation curl https://www.ipplus360.com/getLocation
|
详情响应
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| { "code": "Success", "data": { "continent": "大洋洲", "country": "澳大利亚", "zipcode": "2000", "timezone": "UTC+10", "accuracy": "城市", "owner": "Linode", "isp": "阿卡迈", "source": "数据挖掘", "areacode": "AU", "adcode": "", "asnumber": "63949", "lat": "-33.871675", "lng": "151.211365", "radius": "", "prov": "新南威尔士州", "city": "悉尼", "district": "" }, "charge": false, "msg": "查询成功", "ip": "123.123.123.123", "coordsys": "WGS84" }
|
CSDN
国内站 searchplugin.csdn.net
响应为 json,不需要 ua
获取当前 ip 和地址,浏览器访问会有缓存,接口访问正常
1 2
| https://searchplugin.csdn.net/api/v1/ip/get curl https://searchplugin.csdn.net/api/v1/ip/get
|
获取指定 ip 信息
1 2
| https://searchplugin.csdn.net/api/v1/ip/get?ip= curl https://searchplugin.csdn.net/api/v1/ip/get?ip=
|
响应
1 2 3 4 5 6 7 8
| { "code": 200, "msg": "success", "data": { "address": "XTOM.COM XTOM.COM xtom.com", "ip": "185.222.222.222" } }
|
cip.cc
测国内地理位置是准的,国外不准
http://www.cip.cc/
1 2 3 4 5 6 7 8 9 10 11 12
| curl cip.cc
IP : 124.222.213.111 地址 : 中国 北京 运营商 : srit.com.cn
数据二 : 上海市 | 腾讯云
数据三 : 中国北京北京市 | 联通
URL : http://www.cip.cc/124.222.213.111
|
ipidea
一个代理网站的测试地址
https://ipinfo.ipidea.io/
1 2
| {"ip":"148.135.53.85","country_code":"US","province":"California","city":"Los Angeles","zip_code":"90009","asn":"AS35916","asn_name":"MULTACOM CORPORATION","asn_type":"hosting","timezone":"America/Los_Angeles","longitude":"-118.24368","latitude":"34.05223"}
|
国外 API
geojs.io
GeoJS | GeoJS · REST/JSON/JSONP GeoIP API
支持ip、country、geo、ptr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| https://get.geojs.io/v1/ip https://get.geojs.io/v1/ip.json
https://get.geojs.io/v1/ip/country{/ip address} https://get.geojs.io/v1/ip/country/full{/ip address} https://get.geojs.io/v1/ip/country.json https://get.geojs.io/v1/ip/country/{ip address}.json
https://get.geojs.io/v1/ip/geo.json https://get.geojs.io/v1/ip/geo/{ip address}.json
https://get.geojs.io/v1/dns/ptr https://get.geojs.io/v1/dns/ptr/{ip address} https://get.geojs.io/v1/dns/ptr.json https://get.geojs.io/v1/dns/ptr/{ip address}.json
|
ip.sb
地址还算准
API 文档:API - IP.SB
获取公网 ip
1 2 3 4 5 6 7 8 9 10 11 12 13
| # api 纯文本,公网 ip https://api.ip.sb/ip
# curl curl ip.sb
# 仅侦听 IPv4 https://api-ipv4.ip.sb/ip curl -4 ip.sb或curl ipv4.ip.sb
# 仅收听 IPv6 https://api-ipv6.ip.sb/ip curl -6 ip.sb或curl ipv6.ip.sb
|
获取详细信息
/geoip
接口
地区比较准,但是直接请求访问不通,要添加 ua
获取当前 ip 信息
1 2 3
| https://api.ip.sb/geoip
curl 'https://api.ip.sb/geoip' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
|
获取指定 ip 信息
1 2 3
| https://api.ip.sb/geoip/185.222.222.222
curl 'https://api.ip.sb/geoip/185.222.222.222' -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'
|
响应
1 2 3 4 5 6 7 8 9 10 11 12
| { "organization": "xTom", "longitude": 8, "timezone": "Europe/Vaduz", "isp": "xTom", "offset": 3600, "asn": 6233, "asn_organization": "XTOM", "ip": "185.222.222.222", "latitude": 47, "continent_code": "EU" }
|
ipinfo.io
国内地理位置获取不准
1 2 3 4 5 6 7 8 9 10 11 12 13
| # 获取当前ip https://ipinfo.io/ip curl ipinfo.io/ip
# 获取当前ip详细信息 https://ipinfo.io/json curl ipinfo.io/json
# 查询某个字段,可以在域名后单独接字段,例如查询当前国家 curl ipinfo.io/country
# 指定ip详细信息 curl https://ipinfo.io/185.222.222.222
|
响应
1 2 3 4 5 6 7 8 9 10 11 12 13
| { "ip": "185.222.222.222", "hostname": "public-dns-a.dns.sb", "anycast": true, "city": "Düsseldorf", "region": "North Rhine-Westphalia", "country": "DE", "loc": "51.2217,6.7762", "org": "AS6233 xTom", "postal": "40210", "timezone": "Europe/Berlin", "readme": "https://ipinfo.io/missingauth" }
|
httpbin.org
获取当前 ip,国内响应慢
测试当前 IP
如果代理走 Rule 模式时,可以分别来测一下国内外当前使用的 IP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import requests
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36'} proxies = { "http": "http://127.0.0.1:7890/", "https": "http://127.0.0.1:7890/" } res = requests.get('https://api.ip.sb/geoip', proxies=proxies, headers=headers).json() res_dic = {'country': res['country'], 'city': res['city'], 'ip': res['ip']} print('国外API测试', res_dic) res = requests.get('https://qifu-api.baidubce.com/ip/local/geo/v1/district', proxies=proxies).json() ip = res['ip'] data = res['data'] res_dic = {'country': data['country'], 'city': data['city'], 'ip': ip} print('国内API测试', res_dic)
|