IP查询接口及其简单使用方法(保持更新)

参考另一文档《IP地址查询接口2021版

需要用到IP查询接口,发现原来的接口好多都不能用了,比如小气的腾讯。

这里分享几个目前能用的,大家各取所需吧。

太平洋IP地址库API接口

*. 请求接口(GET):

http://whois.pconline.com.cn/?ip=[ip地址]
http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=[ip地址]

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

*. 返回示例 Json

{"ip":"61.235.82.163","pro":"广东省","proCode":"440000","city":"广州市","cityCode":"440100","region":"天河区","regionCode":"440106","addr":"广东省广州市天河区 蓝色心情网吧","regionNames":"","err":""}

聚合数据IP地址接口

每天免费50次查询,介绍:https://www.juhe.cn/docs/api/id/1

*. 请求接口:

http://apis.juhe.cn/ip/ipNewV3?ip=[ip地址]

*. 返回示例 Json

{"resultcode":"200","reason":"查询成功","result":{"Country":"中国","Province":"广东","City":"广州","District":"","Isp":"铁通"},"error_code":0}

api.vore.top查询接口

没有频率限制,自动区分IPv4和IPv6

*. 请求接口(GET):

https://api.vore.top/api/IPdata?ip=[ip地址]

*. 请求示例

https://api.vore.top/api/IPdata?ip=117.136.12.79
https://api.vore.top/api/IPdata?ip=2409:895c:8a04:32f5:c5dc:a521:ba06:cf56

*. 返回示例 Json

{"code":200,"msg":"SUCCESS","ipinfo":{"type":"ipv6","text":"2409:895c:3204:50a2:4dc2:1d06:8ed7:6148","cnip":false},"ipdata":{"info1":"广西区","info2":"桂林市","info3":"七星区","isp":"移动"},"adcode":{"o":"广西区桂林市七星区 - 移动","p":"广西区","c":"桂林","n":"广西区-桂林","r":null,"a":null,"i":false},"tips":"接口由VORE-API(https:\/\/api.vore.top\/)免费提供","time":1689758892}

api.mir6.com查询接口

自动区分IPv4和IPv6、域名,介绍:https://api.mir6.com/doc/ip_json.html

*. 请求接口(GET):

https://api.mir6.com/api/ip_json?ip=[ip地址]

*. 请求示例

https://api.vore.top/api/IPdata?ip=117.136.12.79
https://api.vore.top/api/IPdata?ip=2409:895c:8a04:32f5:c5dc:a521:ba06:cf56
https://api.mir6.com/api/ip_json?ip=www.qq.com

*. 返回示例 Json

{"code":200,"msg":"success","data":{"ip":"240e:97c:2f:3003::77","dec":"47925092370312089887601455778723004535","country":"中国","countryCode":"CN","province":"广东省","city":"广州市","districts":"","idc":"","isp":"中国电信","net":"数据中心","zipcode":"510000","areacode":"020","protocol":"IPv6","location":"中国[CN] 广东省 广州市","myip":"222.137.131.250","time":"2023-07-19 17:33:46"}}

ip-api.com接口

官网:https://ip-api.com/docs/api:json

*. 请求接口(GET):

http://ip-api.com/json/[ip地址]
http://ip-api.com/json/[ip地址]?lang=zh-CN

*. 返回示例 Json

{"status":"success","country":"China","countryCode":"CN","region":"GD","regionName":"Guangdong","city":"Xiaolou","zip":"","lat":23.379,"lon":113.763,"timezone":"Asia/Hong_Kong","isp":"China Railway Telecommunications","org":"","as":"AS38370 China TieTong Telecommunications Corporation","query":"61.235.82.163"}

若是在接口添加了 ?lang=zh-CN 则返回如下

{"status":"success","country":"中国","countryCode":"CN","region":"GD","regionName":"广东","city":"小楼","zip":"","lat":23.379,"lon":113.763,"timezone":"Asia/Hong_Kong","isp":"China Railway Telecommunications","org":"","as":"AS38370 China TieTong Telecommunications Corporation","query":"61.235.82.163"}

淘宝IP地址库【已失效

*. 网址:http://ip.taobao.com/

*. 请求接口(GET):

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

*. 返回数据格式:(json格式的)国家 、省(自治区或直辖市)、市(县)、运营商。例如:

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

*.  淘宝IP接口使用示例PHP版:

<?php
$ip=get_ip_data();
function get_ip_data(){
	$ip=file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".get_client_ip());
	$ip = json_decode($ip);
	if($ip->code){
		return false;
	}
	$data = (array) $ip->data;
	print_r($data);//return $data;
}

//取客户端 ip
function get_client_ip(){
	if (isset($_SERVER['HTTP_CLIENT_IP']) and !empty($_SERVER['HTTP_CLIENT_IP'])){
		return $_SERVER['HTTP_CLIENT_IP'];
	}
	if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and !empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
		return strtok($_SERVER['HTTP_X_FORWARDED_FOR'], ',');
	}
	if (isset($_SERVER['HTTP_PROXY_USER']) and !empty($_SERVER['HTTP_PROXY_USER'])){
		return $_SERVER['HTTP_PROXY_USER'];
	}
	if (isset($_SERVER['REMOTE_ADDR']) and !empty($_SERVER['REMOTE_ADDR'])){
		return $_SERVER['REMOTE_ADDR'];
	} else {
		return "0.0.0.0";
	}
}
?>

新浪IP地址查询接口【已失效

*. 请求接口(GET):

http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=[ip地址]

注:参数format可设置返回格式:js/json;参数ip可选查询IP;

*.  返回格式如下:

var remote_ip_info = {"ret":1,"start":"125.40.0.0","end":"125.40.111.255","country":"\u4e2d\u56fd","province":"\u6cb3\u5357","city":"\u90d1\u5dde","district":"","isp":"\u8054\u901a","type":"","desc":""};

下面的实例用到了JQuery下的getScript()方法

<div id="sina_ip_info"></div>
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var uip = '8.8.8.8';
$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip='+uip, function(_result){
	var ipData = ""; //初始化保存内容变量
	if (remote_ip_info.ret == '1'){
		ipData += "IP 详细信息:<br>";
		ipData += "IP:" + uip + "<br>";
		ipData += "国家:" + remote_ip_info.country + "<br>";
		ipData += "省份:" + remote_ip_info.province + "<br>";
		ipData += "城市:" + remote_ip_info.city + "<br>";
		ipData += "区:" + remote_ip_info.district + "<br>";
		ipData += "ISP:" + remote_ip_info.isp + "<br>";
		ipData += "类型:" + remote_ip_info.type + "<br>";
		ipData += "其他:" + remote_ip_info.desc + "<br>";
		$("#sina_ip_info").html(ipData); //显示处理后的数据
	} else {
		alert('错误', '没有找到匹配的 IP 地址信息!');
	}
});
</script>

搜狐IP地址查询接口(默认编码GBK)

*. 请求接口(GET):

http://pv.sohu.com/cityjson?ie=utf-8

稳定付费的接口

聚合数据

https://www.juhe.cn/docs/api/id/1

阿里云

云市场,价格不贵

https://market.aliyun.com/

站长之家

https://www.chinaz.net/mall/a_T9wERBm9NZ.html