我也在这里卡了半天,结果去翻Cloudflare的文档才知道只有邮箱还不能确定什么域什么记录,所以这个是zone id
例如
#!/bin/bash
export API_TOKEN="你的 Cloudflare API Token"
# 1. 先获取所有 zones,找到你的域名对应的 zone
curl -s "https://api.cloudflare.com/client/v4/zones" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" | jq '.result[] | {name: .name, id: .id}'
# 2. 找到你的域名后,获取该域名的 DNS 记录
# 假设你的 zone_id 是 "xxxxxx",然后:
curl -s "https://api.cloudflare.com/client/v4/zones/xxxxxx/dns_records" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" | jq '.result[] | {name: .name, id: .id, type: .type}'
# 3. 找到记录 id 后,再更新
# 记得把 RECORD_ID 替换成实际记录的 ID
curl -s -X GET \
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \
-H "Authorization: Bearer ${API_TOKEN}" \
-H "Content-Type: application/json" | \
jq -r '.result.content'
这样才能得到精确的DNS记录条目