IP查询服务 - 获取公网IP、归属地、运营商、应用场景等信息
本API提供IP相关信息的查询服务,包括获取公网IP、查询指定IP的详细信息等功能。所有接口均支持跨域访问。
仅获取当前公网IP地址,直接返回纯文本格式。
无
114.114.114.114
无法获取公网IP
根据指定的IP地址获取其详细信息,包括归属地、运营商、应用场景等。
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ip | string | 是 | 要查询的IP地址 |
{
"归属地": "US California Mountain View",
"运营商": "AS15169 Google LLC",
"经纬度": "37.3860,-122.0840",
"时区": "America/Los_Angeles",
"应用场景": "云服务器"
}
{"error": "无法获取IP详细信息"}
获取服务器公网IP及其详细信息(组合了 /api/ip 和 /api/ip-info/:ip 的功能)。
无
{
"ip": "123.45.67.89",
"归属地": "CN Guangdong Shenzhen",
"运营商": "China Mobile",
"经纬度": "22.5431,114.0579",
"时区": "Asia/Shanghai",
"应用场景": "移动网络"
}
{"error": "无法获取IP信息"}
| 字段名 | 类型 | 描述 |
|---|---|---|
| ip | string | IP地址 |
| 归属地 | string | 国家 地区 城市 |
| 运营商 | string | 网络服务提供商信息 |
| 经纬度 | string | 地理位置坐标,格式为"纬度,经度" |
| 时区 | string | 时区信息 |
| 应用场景 | string | 根据运营商信息推断的应用场景(云服务器、宽带、移动网络等) |
// 获取公网IP
fetch('/api/ip')
.then(response => response.text())
.then(ip => console.log('公网IP:', ip))
.catch(error => console.error('Error:', error));
// 查询指定IP信息
fetch('/api/ip-info/8.8.8.8')
.then(response => response.json())
.then(data => console.log('IP信息:', data))
.catch(error => console.error('Error:', error));
// 获取公网IP及详细信息
fetch('/api/public-ip-info')
.then(response => response.json())
.then(data => console.log('公网IP信息:', data))
.catch(error => console.error('Error:', error));
import requests
# 获取公网IP
response = requests.get('http://your-server.com/api/ip')
ip = response.text
print('公网IP:', ip)
# 查询指定IP信息
response = requests.get('http://your-server.com/api/ip-info/8.8.8.8')
data = response.json()
print('IP信息:', data)
# 获取公网IP及详细信息
response = requests.get('http://your-server.com/api/public-ip-info')
data = response.json()
print('公网IP信息:', data)
# 获取公网IP curl http://your-server.com/api/ip # 查询指定IP信息 curl http://your-server.com/api/ip-info/8.8.8.8 # 获取公网IP及详细信息 curl http://your-server.com/api/public-ip-info
A: 由于使用第三方API,建议控制调用频率,避免短时间内大量请求。
A: 检查返回的error字段获取错误原因,适当进行重试或提示用户。
A: 信息来源于第三方API,基本准确,但可能存在延迟或偏差。