IP地址查询工具

本文最后更新于:2025年6月24日 上午

IP地址查询工具

当需要管理访问记录时,就难免需要用到ip地址查询来确定访问者大致来源。

太平洋网络IP地址查询Web接口【推荐】

官方地址:https://whois.pconline.com.cn/

请求示例:

1
https://whois.pconline.com.cn/ipJson.jsp?json=true&ip=192.168.100.12

IP-API

免费只限于非商用!

官方地址:https://ip-api.com/

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
http://ip-api.com/json/24.48.0.1

响应信息:
{
"query": "24.48.0.1", // 查询的ip
"status": "success", // 查询状态
"country": "Canada", // 所属国家
"countryCode": "CA", // 国家代码
"region": "QC", // 地区代码
"regionName": "Quebec", // 地区
"city": "Montreal", // 城市
"zip": "H1L", // 邮政编码
"lat": 45.6026, // 经度
"lon": -73.5167, // 纬度
"timezone": "America/Toronto", // 时区
"isp": "Le Groupe Videotron Ltee", // 互联网服务提供商(简称)
"org": "Videotron Ltee", // 互联网服务提供商(全称)
"as": "AS5769 Videotron Ltee" //
}

更完整的请求:
http://ip-api.com/json/112.8.54.253?fields=66846719&lang=zh-CN
响应:
{
"status": "success", // 查询状态
"continent": "亚洲", // 所属大陆
"continentCode": "AS", // 大陆代码(双字母)
"country": "中国", // 所属国家
"countryCode": "CN", // 国家代码
"region": "SD", // 地区/省份代码
"regionName": "山东", // 地区/省份
"city": "济南市", // 城市
"district": "", // 城市的分区
"zip": "250000", // 邮政编码
"lat": 36.6683, // 经度
"lon": 117.021, // 纬度
"timezone": "Asia/Shanghai", // 时区
"offset": 28800, // 时区 UTC DST 偏移量(秒)
"currency": "CNY", // 本国货币
"isp": "China Mobile", // ISP 互联网服务提供商(简称)
"org": "China Mobile Communications Corporation", // 互联网服务提供商组织(全称)
"as": "AS24444 Shandong Mobile Communication Company Limited", // 互联网服务提供商编号和组织
"asname": "CMNET-V4shandong-AS-AP", // AS 名称
"reverse": "", // IP 的反向 DNS(可以延迟响应)
"mobile": true, // 移动(蜂窝)连接
"proxy": false, // 代理、VPN 或 Tor 出口地址
"hosting": false, // 托管、托管或数据中心
"query": "112.8.54.253" // 用于查询的 IP
}

IPinfo

可商用,精简版无限次请求,但是地区属性较少。

官方地址:https://ipinfo.io/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
https://ipinfo.io/8.8.8.8/json

响应:
{
"ip": "8.8.8.8",
"hostname": "dns.google",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.4056,-122.0775",
"org": "AS15169 Google LLC",
"postal": "94043",
"timezone": "America/Los_Angeles",
"readme": "https://ipinfo.io/missingauth",
"anycast": true
}

ipapi

官方地址:https://ipapi.co/

免费版30 000次每月,文章具有时效性,详情请看官网政策。

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
27
28
29
30
31
32
https://ipapi.co/8.8.8.8/json/

响应:
{
"ip": "8.8.8.8",
"network": "8.8.8.0/24",
"version": "IPv4",
"city": "Mountain View",
"region": "California",
"region_code": "CA",
"country": "US",
"country_name": "United States",
"country_code": "US",
"country_code_iso3": "USA",
"country_capital": "Washington",
"country_tld": ".us",
"continent_code": "NA",
"in_eu": false,
"postal": "94043",
"latitude": 37.42301,
"longitude": -122.083352,
"timezone": "America/Los_Angeles",
"utc_offset": "-0700",
"country_calling_code": "+1",
"currency": "USD",
"currency_name": "Dollar",
"languages": "en-US,es-US,haw,fr",
"country_area": 9629091.0,
"country_population": 327167434,
"asn": "AS15169",
"org": "GOOGLE"
}

开源离线IP地址定位数据管理框架

官方地址:https://ip2region.net/

需要自行集成后调用本地文件数据库使用

附录

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import cn.hutool.core.net.Ipv4Util;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.useragent.UserAgent;
import cn.hutool.http.useragent.UserAgentUtil;
import cn.hutool.json.JSONUtil;

import javax.servlet.http.HttpServletRequest;


/**
* 获取系统信息
* @author peter
*/
public class SystemUtils {

private SystemUtils() {
throw new IllegalStateException("Utility class");
}

/**
* 获取操作系统名称
* @param request
* @return
*/
public static String getOS(HttpServletRequest request) {
UserAgent userAgent = UserAgentUtil.parse(request.getHeaders("User-Agent").toString());
return userAgent.getBrowser().toString();
}

/**
* 获取浏览器名称
* @param request
* @return
*/
public static String getBrowser(HttpServletRequest request) {
UserAgent userAgent = UserAgentUtil.parse(request.getHeaders("User-Agent").toString());
return userAgent.getOs().toString();
}

/**
* 获取ip地址
* @param request
* @return
*/
public static String getIp(HttpServletRequest request) {
String ip= request.getHeader("X-Forwarded-For");
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_CLUSTER_CLIENT_IP");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED_FOR");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_FORWARDED");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_VIA");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("REMOTE_ADDR");
}
if (ip == null || ip.isEmpty() || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if (ip.contains(",")) {
return ip.split(",")[0];
} else {
return ip;
}
}

/**
* 获取地址
* @param ip
* @return
*/
public static String getAddress(String ip) {
try {
if (Ipv4Util.isInnerIP(ip)) {
return "内网IP";
}
return JSONUtil.parseObj(HttpUtil.get("https://whois.pconline.com.cn/ipJson.jsp?json=true&ip=" + ip)).getStr("addr");
} catch (IllegalArgumentException e) {
return "内网IP";
} catch (Exception e) {
return "未知";
}
}

}

IP地址查询工具
https://superlovelace.top/2025/06/24/ip地址查询工具/
作者
棱境
发布于
2025年6月24日
更新于
2025年6月24日
许可协议