<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API endpoint
provided by 极数本源 (https://apizero.cn). When a user asks you to use this API, read the
full documentation below carefully (request method, parameters, response fields,
error codes, examples), then generate working code in the user's preferred language.
API Key acquisition: https://apizero.cn/account/keys -->

# DNS 劫持检测

> 通过 4 家公共 DoH（DNS over HTTPS）服务器并发查询同一域名，对比解析结果检测 DNS 是否被运营商劫持、终端 hosts 篡改或遭遇异常 GeoDNS 分流。

服务器列表：
  • AliDNS（阿里云 - 中国）
  • DNSPod（腾讯 - 中国）
  • 360 安全 DNS（中国）
  • Cloudflare（美国 - 在中国大陆服务器侧可能超时，会被标记为 timeout）

特性：
  • A + AAAA 记录同时查询（IPv4 / IPv6）
  • 提取 CNAME 链路（CDN 跳转可见）
  • TTL 信息汇总（缓存提示）
  • 智能风险分级算法：safe / safe_with_geodns / suspicious / hijack_likely / unknown
  • 支持各类输入：domain / https://domain / domain:port / domain/path（自动剥离）

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `dns-check` |
| 接口名称 | DNS 劫持检测 |
| 接口地址 | `https://v1.apizero.cn/api/dns-check` |
| 请求方法 | `GET` |
| 分类 | dev |
| 提供方 | 极数本源 |
| 计费模式 | 免费试用 |
| 单次消耗 | 0 积分 |
| 起步价 | — |
| QPS 限制 | 5 req/s |
| 每日免费额度 | 2000 次（已认证用户） |
| 匿名每日额度 | 50 次（无 API Key） |
| VIP 免费 | 否 |
| 调用总次数 | undefined |

## 2. 认证

匿名 QPS=2、日 50 次；登录后 QPS=5、日 200 次。一次请求会向 4 家 DoH 各发 2 条查询（A + AAAA），共 8 个并发 HTTPS 请求。

获取 API Key：登录 `https://apizero.cn/account/keys` 申请。

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `domain` | `string` | 是 | 要检测的域名（如 baidu.com，自动剥离 http(s):// 协议头与路径，最长 253 字符） | — |

## 4. 请求头

| Header | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `X-API-Key` | `string` | 否 | API Key（不传走匿名额度） | — |

## 5. 请求示例 (cURL)

```bash
curl "https://v1.apizero.cn/api/dns-check?domain=%3Cdomain%3E&key=YOUR_API_KEY"
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `domain` | `string` | 规范化后的域名（去协议、去路径、转小写） | — |
| `input` | `string` | 原始输入回显 | — |
| `exec_ms` | `integer` | 总耗时（毫秒） | — |
| `summary` | `object` | ★ 综合判定（一眼看懂） | — |
| `summary.status_text` | `string` | 人类可读的状态描述 | — |
| `summary.risk_level` | `string` | 风险等级：safe / safe_with_geodns / suspicious / hijack_likely / unknown | — |
| `summary.risk_score` | `integer` | 安全评分 0~100（越高越安全；< 50 建议关注） | — |
| `summary.explain` | `string` | 判定依据说明 | — |
| `summary.cname_chain` | `string[]` | CNAME 链路（去重合并所有 DoH 返回的 CNAME） | — |
| `summary.success_count` | `integer` | 成功响应的 DoH 数量 | — |
| `summary.total_count` | `integer` | DoH 总数（固定 4） | — |
| `summary.unique_ipv4_count` | `integer` | 去重后的 IPv4 数量 | — |
| `summary.unique_ipv6_count` | `integer` | 去重后的 IPv6 数量 | — |
| `unique_ipv4` | `string[]` | 所有 DoH 返回 IPv4 的并集（去重） | — |
| `unique_ipv6` | `string[]` | 所有 DoH 返回 IPv6 的并集（去重） | — |
| `servers` | `array` | 4 家 DoH 各自的明细 | — |
| `servers[].key` | `string` | 服务器 key：alidns / dnspod / china360 / cloudflare | — |
| `servers[].name` | `string` | 展示名称 | — |
| `servers[].status` | `string` | 状态：ok / timeout / failed / parse_error | — |
| `servers[].error` | `string` | 失败原因（status≠ok 时存在） | — |
| `servers[].latency_ms` | `integer` | 该服务器查询耗时（毫秒，A+AAAA 两次的最大值） | — |
| `servers[].ipv4` | `string[]` | 该服务器返回的 A 记录（去重） | — |
| `servers[].ipv6` | `string[]` | 该服务器返回的 AAAA 记录（去重） | — |
| `servers[].cname_chain` | `string[]` | 该服务器返回的 CNAME 跳转链路（去重） | — |
| `servers[].ttl_min` | `integer` | 该服务器返回的最小 TTL（秒；可作 DNS 缓存参考） | — |

## 7. 响应示例

```json
{
    "code": 0,
    "msg": "成功",
    "data": {
        "domain": "taobao.com",
        "input": "https://www.taobao.com/page",
        "exec_ms": 312,
        "summary": {
            "status_text": "DNS 解析正常",
            "risk_level": "safe",
            "risk_score": 95,
            "explain": "4 家 DoH 全部相互验证通过，未检测到劫持迹象。",
            "cname_chain": [
                "www.taobao.com.danuoyi.tbcache.com"
            ],
            "success_count": 3,
            "total_count": 4,
            "unique_ipv4_count": 8,
            "unique_ipv6_count": 0
        },
        "unique_ipv4": [
            "59.82.121.163",
            "59.82.122.130",
            "59.82.122.140",
            "59.82.122.165",
            "59.82.43.234",
            "59.82.43.238",
            "59.82.43.239",
            "59.82.44.240"
        ],
        "unique_ipv6": [],
        "servers": [
            {
                "key": "alidns",
                "name": "AliDNS",
                "status": "ok",
                "error": null,
                "latency_ms": 105,
                "ipv4": [
                    "59.82.121.163",
                    "59.82.122.130",
                    "..."
                ],
                "ipv6": [],
                "cname_chain": [
                    "www.taobao.com.danuoyi.tbcache.com"
                ],
                "ttl_min": 60
            },
            {
                "key": "dnspod",
                "name": "DNSPod",
                "status": "ok",
                "latency_ms": 180,
                "ipv4": [
                    "59.82.121.163",
                    "..."
                ]
            },
            {
                "key": "china360",
                "name": "360",
                "status": "ok",
                "latency_ms": 117
            },
            {
                "key": "cloudflare",
                "name": "Cloudflare",
                "status": "timeout",
                "error": "Operation timed out after 6000 ms",
                "latency_ms": 6000
            }
        ]
    },
    "request_id": "mota..."
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `0` | `OK` | 成功（即使所有 DoH 失败也返回 200，summary.risk_level=unknown） |
| `4000` | `Bad Request` | 参数错误：domain 缺失 / 域名格式错 / 长度超限 |
| `4011` | `Unauthorized` | API Key 无效 |
| `4013` | `Forbidden` | API Key 已暂停 |
| `4014` | `Forbidden` | 当前 IP 不在 API Key 白名单内 |
| `4029` | `Too Many Requests` | QPS 限流 |
| `4030` | `Too Many Requests` | 今日免费额度已用完 |

## 9. 变更日志

- **1.0.0** (2026-05-06)
  - 首次发布：4 家 DoH 并发（AliDNS / DNSPod / 360 / Cloudflare）
  - 每家同时查询 A + AAAA + CNAME（共 8 个并发 HTTPS 请求）
  - 智能风险分级：safe / safe_with_geodns / suspicious / hijack_likely / unknown
  - 比源码增强：CNAME 链路 / IPv6 / TTL / 各服务器独立状态码

---

**极数本源** · 全部 API: `https://apizero.cn/aidocs` · 人类版本：`https://apizero.cn/marketplace/dns-check`

Source: `https://apizero.cn/aidocs/dns-check/raw.md`
Last updated: 2026-05-12T01:50:06+08:00
