分享2020 几个好用的ip地址归属地查询
生活随笔
收集整理的這篇文章主要介紹了
分享2020 几个好用的ip地址归属地查询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
ip地址歸屬地查詢接口
一、百度
大公司,不必說,肯定好用,我就一直用的他作為主要查詢接口。
url:http://opendata.baidu.com/api.php
params:query=ip,resource_id=6006,format=json
拼接之后url:
http://opendata.baidu.com/api.php?query=48.102.123.25&resource_id=6006&format=json
返回結果示例:
注意: format是返回結果,支持json,xml,json返回結果中,status=0表示請求成功,但是不表示有數據返回,data集合不為空才表示查詢成功
二、太平洋
很好用,備用ip查詢
http://whois.pconline.com.cn/ipJson.jsp?ip=xxx.xxx.xxx.xxx&json=true
返回結果示例:
如果請求的ip為不正確的ip,返回結果是本機ip的外網ip的歸屬地
更多詳情請訪問:http://whois.pconline.com.cn/
三、純真
官網:http://www.cz88.net/
http://ipaddr.cz88.net/data.php?ip=47.102.123.89
返回結果示例:jsonp
注意: 偶爾會訪問錯誤
非公網ip的ABC類地址
局域網地址范圍分三類,以下IP段為內網IP段:
C類:192.168.0.0 - 192.168.255.255
B類:172.16.0.0 - 172.31.255.255
A類:10.0.0.0 - 10.255.255.255
環回地址:127.0.0.0-127.255.255.255
附上Java版本的非公網ip判斷代碼
public static boolean isLocalIp(String ip) {String prefixA = "10.";String prefixB = "172.";String prefixC = "192.168.";String prefixLH = "127.";if (ip.startsWith(prefixC) || ip.startsWith(prefixA)) {return true;}if (ip.startsWith(prefixB)) {// 截取 第二個字節String str = ip.substring(ip.indexOf(".") + 1);int c = Integer.parseInt(str.substring(0, str.indexOf(".")));return c > 15 && c < 32;}return ip.startsWith(prefixLH);}
最后正則表達式版本:
public static boolean isLocalIp(String ip) {String pattern = "^192.168.|^10.|^127.|^172.(1[6-9]|2[0-9]|3[0-1]).";// 創建 Pattern 對象Pattern p = Pattern.compile(pattern);// 現在創建 matcher 對象return p.matcher(ip).find();}
注意:淘寶的api已經炸了
總結
以上是生活随笔為你收集整理的分享2020 几个好用的ip地址归属地查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Springboot 多文件上传
- 下一篇: Springboot 利用AOP编程实现