接口说明
请求参数
| 参数 | 必填 | 说明 |
| ip | 否 | 要查询的 IP,IPv4 / IPv6 均可。多个用英文逗号分隔。不传则查询请求方自己的 IP |
| format | 否 | json(默认)/ text 纯文本 / jsonp 跨域回调 |
| callback | 否 | 配合 format=jsonp 使用,回调函数名 |
| type | 否 | 1 打开本页面,3 返回库信息(版本、条数、字段) |
| key | 否 | 接口密钥,仅在源码里设置了 API_KEY 后校验 |
返回字段
| 字段 | 说明 |
| ip | 查询的 IP |
| ip_version | 4 或 6 |
| country | 国家名称 |
| province | 省份(国外为州/区域) |
| city | 城市 |
| district | 区县 |
| isp | 运营商 / 机构名称 |
| country_code | ISO 国家代码,如 CN、US |
| continent | 大洲代码,如 AS、NA |
| area | 省+市 拼接,如「江苏南京」 |
| location | 完整地理位置,如「中国 江苏 南京」 |
| text | 一行完整文本:国家 省 市 区县 运营商 |
| is_china | 是否中国大陆,布尔值 |
返回示例
{
"code": 200,
"msg": "success",
"data": {
"ip": "114.114.114.114",
"ip_version": 4,
"country": "中国",
"province": "江苏",
"city": "南京",
"district": "",
"isp": "南京信风网络科技有限公司GreatbitDNS服务器",
"country_code": "CN",
"continent": "AS",
"area": "江苏南京",
"location": "中国 江苏 南京",
"is_china": true,
"text": "中国 江苏 南京 南京信风网络科技有限公司GreatbitDNS服务器",
"owner_domain": ""
},
"ms": 0.71
}
调用示例
# 命令行
curl "https://ip.zgyw.top/ip.php?ip=114.114.114.114"
# 纯文本(适合直接显示)
curl "https://ip.zgyw.top/ip.php?ip=114.114.114.114&format=text"
# IPv6
curl "https://ip.zgyw.top/ip.php?ip=2400:3200::1"
# 批量
curl "https://ip.zgyw.top/ip.php?ip=8.8.8.8,1.1.1.1,223.5.5.5"
// 浏览器 / 小程序
fetch('https://ip.zgyw.top/ip.php?ip=114.114.114.114')
.then(r => r.json())
.then(res => console.log(res.data.location, res.data.isp));
// PHP
$r = json_decode(file_get_contents('https://ip.zgyw.top/ip.php?ip=114.114.114.114'), true);
echo $r['data']['location'];
# Python
import requests
r = requests.get('https://ip.zgyw.top/ip.php', params={'ip': '114.114.114.114'}).json()
print(r['data']['text'])
状态码
| code | 说明 |
| 200 | 成功 |
| 400 | 参数错误,IP 格式不正确或为空 |
| 403 | API Key 无效(仅当开启了密钥校验) |
| 404 | 库中没有该 IP 的记录 |
| 429 | 超出频率限制 |
| 500 | 数据库文件缺失或损坏 |
使用须知
- 内网 IP 会直接标记为「内网/保留地址」,不走数据库,比如 127.0.0.1、192.168.x.x、::1。
- IPv4 映射地址 如
::ffff:1.2.3.4 会自动按 IPv4 查询。
- 定位精度 到城市级,运营商 IDC 机房可能只到省级,属正常现象。
- 库更新 定期替换
data/qqwry.ipdb 即可,接口无需改代码,访问 ?type=3 可看当前库版本。
- 跨域 已默认允许
*,前端可直接调用,无需代理。