📖 使用示例
以下命令中的端点 https://hcfcwwba-mycnu.hf.space/dns-query 已自动替换为您的实际地址,可直接复制运行。
1️⃣ GET 请求 – JSON 格式(?name=)
# A 记录 (IPv4)
curl -H "accept: application/dns-json" \
"https://hcfcwwba-mycnu.hf.space/dns-query?name=google.com&type=A"
# AAAA 记录 (IPv6)
curl -H "accept: application/dns-json" \
"https://hcfcwwba-mycnu.hf.space/dns-query?name=google.com&type=AAAA"
# HTTPS 记录 (ECH 配置)
curl -H "accept: application/dns-json" \
"https://hcfcwwba-mycnu.hf.space/dns-query?name=cloudflare-ech.com&type=HTTPS"
预期:返回 JSON,Answer 中包含对应记录。
2️⃣ GET 请求 – Wire Format(?dns=)
# 查询 google.com A 记录(Base64URL 编码示例)
curl -H "accept: application/dns-message" \
"https://hcfcwwba-mycnu.hf.space/dns-query?dns=AAABAAABAAAAAAAAB2V4YW1wbGUDY29tAAABAAE"
预期:返回二进制 DNS 数据(终端会显示乱码,这是正常的)。
验证响应头:content-type: application/dns-message
3️⃣ POST 请求 – JSON Body
# A 记录查询
curl -X POST -H "Content-Type: application/dns-json" \
-d '{"name":"google.com","type":"A"}' \
"https://hcfcwwba-mycnu.hf.space/dns-query"
# HTTPS 记录查询
curl -X POST -H "Content-Type: application/dns-json" \
-d '{"name":"cloudflare-ech.com","type":"HTTPS"}' \
"https://hcfcwwba-mycnu.hf.space/dns-query"
预期:返回 JSON,Answer 中包含记录。
4️⃣ POST 请求 – 表单格式
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \
-d "name=google.com&type=A" \
"https://hcfcwwba-mycnu.hf.space/dns-query"
预期:返回 JSON,Answer 中包含 IPv4 地址。
5️⃣ POST 请求 – Wire Format(原始二进制)
# 使用 Python 生成二进制查询数据(需安装 Python使用pip install dnspython或pip3 install dnspython命令安装Python)
python3 -c "import dns.message; q = dns.message.make_query('google.com', 'A'); open('query.bin','wb').write(q.to_wire())"
# 发送二进制数据
curl -X POST -H "Content-Type: application/dns-message" \
--data-binary @query.bin \
"https://hcfcwwba-mycnu.hf.space/dns-query"
预期:返回二进制 DNS 响应(终端显示乱码)。
验证响应头:content-type: application/dns-message
🔍 诊断辅助命令
# 查看完整响应头(确认 Content-Type)
curl -I "https://hcfcwwba-mycnu.hf.space/dns-query?name=google.com&type=A"
# 查看 wire format 响应头
curl -I -H "accept: application/dns-message" \
"https://hcfcwwba-mycnu.hf.space/dns-query?dns=AAABAAABAAAAAAAAB2V4YW1wbGUDY29tAAABAAE"
# 保存 wire format 响应到文件(避免终端乱码)
curl -H "accept: application/dns-message" \
"https://hcfcwwba-mycnu.hf.space/dns-query?dns=AAABAAABAAAAAAAAB2V4YW1wbGUDY29tAAABAAE" \
--output response.bin