<!-- 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查询API。自实现DNS协议（RFC 1035），支持A/AAAA/MX/TXT/CNAME/NS/SOA/SRV/PTR/CAA记录类型，UDP自动fallback到DoH（DNS over HTTPS）防劫持。

## 1. 基本信息

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

## 2. 认证

需要 API Key。登录用户每日 50 次免费；匿名每日 30 次。

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

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `domain` | `string` | 是 | 要查询的域名（别名 name/host） | `example.com` |
| `type` | `string` | 否 | 记录类型，逗号分隔；ALL=A,AAAA,MX,TXT,CNAME | `A` |
| `server` | `string` | 否 | 指定DNS服务器（逗号分隔） | `8.8.8.8,1.1.1.1` |
| `timeout` | `int` | 否 | 单请求超时秒（1~30） | `5` |
| `doh` | `int` | 否 | 1=强制走DoH（HTTPS） | `0` |
| `doh_provider` | `string` | 否 | DoH服务商：cloudflare/google/alibaba | `cloudflare` |

## 4. 请求头

| Header | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `Authorization` | `string` | 是 | — | — |

## 5. 请求示例 (cURL)

```bash
curl -X POST "https://v1.apizero.cn/api/dns-lookup" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "domain": "example.com",
  "type": "A",
  "server": "8.8.8.8,1.1.1.1",
  "timeout": "5",
  "doh": "0",
  "doh_provider": "cloudflare"
}'
```

## 6. 响应字段

| 字段 | 类型 | 说明 | 示例 |
| --- | --- | --- | --- |
| `domain` | `string` | 查询的域名 | — |
| `type` | `string` | 查询的记录类型 | — |
| `server` | `string` | 响应的DNS服务器 | — |
| `transport` | `string` | 传输方式（udp/tcp/doh） | — |
| `rcode` | `int` | DNS响应码 | — |
| `rcode_text` | `string` | 响应码文本（NOERROR/NXDOMAIN等） | — |
| `elapsed_ms` | `int` | 查询耗时（毫秒） | — |
| `answers` | `array` | 应答记录数组（type/name/ttl/value） | — |
| `truncated` | `bool` | 是否被截断 | — |

## 7. 响应示例

```json
{
    "code": 0,
    "msg": "成功",
    "data": {
        "domain": "example.com",
        "type": "A",
        "server": "114.114.114.114",
        "transport": "udp",
        "rcode": 0,
        "rcode_text": "NOERROR",
        "elapsed_ms": 32,
        "answers": [
            {
                "type": "A",
                "name": "example.com",
                "ttl": 300,
                "value": "93.184.216.34"
            }
        ],
        "truncated": false
    },
    "request_id": "req_abc123"
}
```

## 8. 错误码

| code | status | 说明 |
| --- | --- | --- |
| `4000` | `—` | 缺少 domain / 非法字符 / 未知 type |
| `5020` | `—` | 全部DNS服务器与DoH都失败 |
| `5021` | `—` | 域名不存在（NXDOMAIN） |

## 9. 变更日志

- **1.0.0** (2026-05-08)
  - 首次上线
  - 支持A/AAAA/MX/TXT/CNAME/NS/SOA/SRV/PTR/CAA
  - UDP+DoH双链路

---

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

Source: `https://apizero.cn/aidocs/dns-lookup/raw.md`
Last updated: 2026-05-08T14:14:53+08:00
