接口文档
查询接口
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /v1/query?ip=223.5.5.5 | 查询单个 IP(IPv4/IPv6 均可);省略 ip 参数时查询调用方 IP。 |
| POST | /v1/query | 批量查询,请求体 {"ips":["223.5.5.5","119.29.29.29","2400:3200::1"]}, IPv4/IPv6 可混排,单次最多 100 个(超出返回 413 too_many_ips),响应为 {"results":[...]}。 |
返回格式
响应均为 application/json。GET 返回单个对象;POST 批量返回{"results":[...]},结果顺序与请求一致,每项结构相同。
| 字段 | 类型 | 说明 |
|---|---|---|
| ip | string | 查询的 IP(IPv4/IPv6 均原样回显) |
| found | boolean | 是否命中;false 表示未收录(内网/保留地址等),不计费 |
| country | string | 国家或地区 |
| province | string | 省份/州,可能为空 |
| city | string | 城市,可能为空 |
| isp | string | 运营商/网络归属,可能为空 |
| country_code | string | ISO 3166-1 alpha-2 国家码,如 CN、US;港澳台统一返回 CN |
# GET /v1/query?ip=223.5.5.5
{
"ip": "223.5.5.5",
"found": true,
"country": "中国",
"province": "浙江省",
"city": "杭州市",
"isp": "阿里",
"country_code": "CN"
}# GET /v1/query?ip=2400:3200::1
{
"ip": "2400:3200::1",
"found": true,
"country": "中国",
"province": "浙江省",
"city": "杭州市",
"isp": "阿里",
"country_code": "CN"
}港澳台说明:香港、澳门、台湾的 IP 统一返回 country=中国、country_code=CN,以 province 区分: 香港特别行政区、澳门特别行政区、台湾省(city 为空)。判断是否中国大陆, 用 province 不属于以上三个值即可。
未命中示例:{"ip":"10.0.0.1","found":false}(不计费)。 每次成功(200)响应带 X-Quota-Remaining 头,为本次扣减后的剩余次数。
鉴权
所有请求需携带请求头 X-API-Key: ipk_your_key(key 在控制台创建)。也支持 ?key= 查询参数,但会进入访问日志,不建议使用。
计费规则
- 仅查询命中(found=true)的结果计费;未命中或 IP 格式非法不计费。
- GET 单次最多计 1 次;POST 批量按响应中 found=true 的个数计费,余量不足时扣至 0。
- 每次成功(200)响应均带
X-Quota-Remaining响应头,表示本次扣减后的剩余次数。 - 次数长期有效,不设有效期。
错误码
| HTTP 状态 | error | 说明 |
|---|---|---|
| 401 | unauthorized | 缺少或无效的 API Key |
| 402 | quota_exhausted | 次数已用完,请充值 |
| 403 | key_disabled | API Key 已被禁用 |
| 404 | not_found | 路径不存在,仅开放 /v1/query |
| 405 | method_not_allowed | 仅支持 GET/POST 查询 |
| 429 | rate_limited | 请求过于频繁,请降低调用频率 |
| 502 | upstream_error | 服务暂时不可用,请稍后重试 |
调用示例
# 单个查询
curl 'https://ip.denys.cn/v1/query?ip=223.5.5.5' -H 'X-API-Key: ipk_your_key'
# IPv6 查询
curl 'https://ip.denys.cn/v1/query?ip=2400:3200::1' -H 'X-API-Key: ipk_your_key'
# 批量查询
curl -X POST 'https://ip.denys.cn/v1/query' \
-H 'X-API-Key: ipk_your_key' \
-H 'Content-Type: application/json' \
-d '{"ips":["223.5.5.5","119.29.29.29"]}'const res = await fetch('https://ip.denys.cn/v1/query?ip=223.5.5.5', {
headers: { 'X-API-Key': 'ipk_your_key' },
})
const data = await res.json()
console.log('剩余次数:', res.headers.get('X-Quota-Remaining'))
console.log(data)import requests
res = requests.get(
"https://ip.denys.cn/v1/query",
params={"ip": "223.5.5.5"},
headers={"X-API-Key": "ipk_your_key"},
)
print(res.json())
print("剩余次数:", res.headers.get("X-Quota-Remaining"))<?php
$ch = curl_init('https://ip.denys.cn/v1/query?ip=223.5.5.5');
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ['X-API-Key: ipk_your_key'],
CURLOPT_RETURNTRANSFER => true,
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
echo $data['country'], ' ', $data['province'], ' ', $data['city'], PHP_EOL;package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
req, _ := http.NewRequest(http.MethodGet, "https://ip.denys.cn/v1/query?ip=223.5.5.5", nil)
req.Header.Set("X-API-Key", "ipk_your_key")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var data map[string]any
json.NewDecoder(resp.Body).Decode(&data)
fmt.Println(data)
}use reqwest::blocking::Client;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let text = Client::new()
.get("https://ip.denys.cn/v1/query?ip=223.5.5.5")
.header("X-API-Key", "ipk_your_key")
.send()?
.text()?;
println!("{text}");
Ok(())
}AI 集成
本站提供 AI 友好的机器可读文档。把下面这段提示词发给你的 AI 编程助手(Claude Code / Cursor / ChatGPT 等),即可正确接入:
我在用 IP 查询 API:基础地址 https://ip.denys.cn,鉴权请求头 X-API-Key(密钥我稍后提供)。 写代码前先抓取 https://ip.denys.cn/llms-full.txt 阅读完整接口说明,严格按其中的端点、响应字段、计费规则与错误码实现。
MCP 远程端点(推荐)
本站提供无状态 MCP 服务(Streamable HTTP,端点 https://ip.denys.cn/mcp, 工具:ip_query / ip_batch /ip_quota),调用按次计费、规则与直调完全一致:
# Claude Code 等 CLI 工具(一行添加)
claude mcp add --transport http ip-denys https://ip.denys.cn/mcp --header "X-API-Key: ipk_your_key"
# Claude Desktop / Cursor 等(mcpServers JSON 配置)
{
"mcpServers": {
"ip-denys": {
"url": "https://ip.denys.cn/mcp",
"headers": { "X-API-Key": "ipk_your_key" }
}
}
}机器可读入口:/llms.txt(站点索引)、/llms-full.txt(完整参考单文件版,推荐 AI 直接读取)。