<!-- 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 记录查询

> 查询域名的各类 DNS 记录，支持 A / AAAA / NS / CNAME / MX / TXT / CAA / SOA 共 8 种标准类型，以及 ANY（一次返回所有类型）。

✨ 特色：
  • 不依赖第三方工具站，完全自建 — 3 家国内 DoH 并发（AliDNS / DNSPod / 360）
  • 所有记录结构化解析：MX 拆 priority/exchange、CAA 拆 flags/tag/value、SOA 拆 mname/serial/...
  • 多家结果合并去重 + 各记录标注来自哪些 DoH（sources 字段）
  • 兼容数字 qtype（如 1=A / 15=MX / 257=CAA），不破坏旧调用方式
  • ANY 模式：单次请求拿到域名的全部 DNS 配置，免去多次查询

## 1. 基本信息

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

## 2. 认证

匿名 QPS=3、日 100；登录 QPS=10、日 500。一次普通查询走 3 个并发 DoH 请求；ANY 模式走 24 个（8 类型 × 3 家）。

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

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `host` | `string` | 是 | 域名（自动剥离 http(s)://、路径、端口） | — |
| `type` | `string` | 否 | 记录类型，默认 A。支持名称（A/AAAA/NS/CNAME/MX/TXT/CAA/SOA/ANY）或数字编码（1/2/5/6/15/16/28/257） | — |

## 4. 请求头

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

## 5. 请求示例 (cURL)

```bash
curl "https://v1.apizero.cn/api/dns-query?host=%3Chost%3E&type=%3Ctype%3E&key=YOUR_API_KEY"
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `host` | `string` | 规范化后的域名 | — |
| `input` | `string` | 原始输入回显 | — |
| `type` | `string` | 请求类型（标准化为大写名称） | — |
| `type_code` | `integer` | 类型数字编码；ANY 模式下为 0 | — |
| `total` | `integer` | 记录总数（去重后） | — |
| `exec_ms` | `integer` | 总耗时（毫秒） | — |
| `sources` | `string[]` | 成功响应的 DoH 列表（alidns/dnspod/china360） | — |
| `notes` | `string\|null` | 提示信息（如未找到记录时） | — |
| `records` | `array` | 记录列表 | — |
| `records[].type` | `string` | 记录类型名（A/AAAA/NS/CNAME/MX/TXT/CAA/SOA） | — |
| `records[].type_code` | `integer` | 类型数字编码 | — |
| `records[].name` | `string` | 记录所属域名 | — |
| `records[].ttl` | `integer` | TTL 秒（多家返回时取最大值） | — |
| `records[].data` | `string` | 原始 rdata 字符串（与 dig 输出一致） | — |
| `records[].parsed` | `object` | ★ 结构化解析结果（详见下方各类型说明） | — |
| `records[].sources` | `string[]` | 哪些 DoH 返回了此条记录 | — |
| `parsed (A/AAAA)` | `object` | { "ip": "111.63.65.103" } | — |
| `parsed (CNAME/NS)` | `object` | { "target": "ns1.baidu.com" }（自动去除末尾点） | — |
| `parsed (MX)` | `object` | { "priority": 10, "exchange": "mx.baidu.com" } | — |
| `parsed (TXT)` | `object` | { "text": "v=spf1 ..." }（去除外层引号 + 拼接长 TXT 段） | — |
| `parsed (CAA)` | `object` | { "flags": 0, "tag": "issue", "value": "digicert.com" } | — |
| `parsed (SOA)` | `object` | { "mname": "ns.foo.com", "rname": "admin.foo.com", "serial": 2024010101, "refresh": 7200, "retry": 3600, "expire": 1209600, "minimum": 600 } | — |

## 7. 响应示例

```json
{
    "code": 0,
    "msg": "成功",
    "data": {
        "host": "baidu.com",
        "input": "baidu.com",
        "type": "MX",
        "type_code": 15,
        "total": 2,
        "exec_ms": 234,
        "sources": [
            "alidns",
            "china360",
            "dnspod"
        ],
        "notes": null,
        "records": [
            {
                "type": "MX",
                "type_code": 15,
                "name": "baidu.com",
                "ttl": 600,
                "data": "10 mx.maillb.baidu.com.",
                "parsed": {
                    "priority": 10,
                    "exchange": "mx.maillb.baidu.com"
                },
                "sources": [
                    "alidns",
                    "china360",
                    "dnspod"
                ]
            },
            {
                "type": "MX",
                "type_code": 15,
                "name": "baidu.com",
                "ttl": 600,
                "data": "20 mx.baidu.com.",
                "parsed": {
                    "priority": 20,
                    "exchange": "mx.baidu.com"
                },
                "sources": [
                    "alidns",
                    "china360",
                    "dnspod"
                ]
            }
        ]
    },
    "request_id": "mota..."
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `0` | `OK` | 成功（即使无匹配记录也返回 200，records 为空数组，notes 给出提示） |
| `4000` | `Bad Request` | 参数错误：host 缺失 / 域名格式错 / type 不合法 |
| `4011` | `Unauthorized` | API Key 无效 |
| `4013` | `Forbidden` | API Key 已暂停 |
| `4014` | `Forbidden` | 当前 IP 不在 API Key 白名单内 |
| `4029` | `Too Many Requests` | QPS 限流 |
| `4030` | `Too Many Requests` | 今日免费额度已用完 |
| `5020` | `Bad Gateway` | 所有 DoH 服务器都失败 |

## 9. 变更日志

- **1.0.0** (2026-05-06)
  - 首次发布：3 家国内 DoH 并发（AliDNS / DNSPod / 360），不依赖第三方工具站
  - 支持 8 种标准类型（A/AAAA/NS/CNAME/MX/TXT/CAA/SOA）+ ANY 一次查全
  - 所有记录附带 parsed 结构化解析（MX/CAA/SOA/TXT 等）
  - 兼容数字 qtype 老接口（1/2/5/6/15/16/28/257）
  - 记录去重：(type, data) 组合 key + sources 字段标注来源

---

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

Source: `https://apizero.cn/aidocs/dns-query/raw.md`
Last updated: 2026-05-11T16:15:07+08:00
