mcpField
T
tencentcloud-dns

tencentcloud-dns

github.com/acedatacloud云与 DevOps17209 次安装今天更新
代码仓库

关于 tencentcloud-dns

tencentcloud-dns 是通过 Tencent Cloud DNS v3 API 管理 DNSPod 记录的技能,可使用命令行脚本或 Python SDK。它支持常见记录操作,并在删除前提供预演确认。

主要功能

  1. 01列出域名和 DNS 记录
  2. 02按类型筛选记录
  3. 03创建和修改记录
  4. 04确认后删除记录
  5. 05处理常见 DNS 记录类型

适用场景

  1. 01添加子域名或验证记录
  2. 02修改 IP 地址或 CNAME 目标
  3. 03检查或删除过时的 DNS 记录

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/acedatacloud/skills --skill tencentcloud-dns

安装后在 Claude Code 中输入/tencentcloud-dns确认已加载。

附带文件scripts/dns.py

详细介绍

DNSPod(Tencent Cloud DNS)

通过 DNSPod API 管理 DNS 记录。

设置:参见 tencentcloud 身份验证。DNSPod 使用与平台其他部分相同的 Tencent Cloud SecretId / SecretKey — v3 API 不需要单独的 DP_Id / DP_Key。下面的 SDK 客户端会自动从环境变量中读取 TENCENTCLOUD_SECRET_ID / TENCENTCLOUD_SECRET_KEY。

旧版 v2 DNSPod API 使用不同的密钥格式;此技能仅面向 v3 SDK。

CLI(首选)

此技能附带 scripts/dns.py — 封装了所有常见的 DNSPod v3 操作。

# $SKILL_DIR can point at another skill loaded this turn — anchor on our own
# script (re-run this at the top of every fresh-shell Bash block).
DNS="$SKILL_DIR/scripts/dns.py"; [ -f "$DNS" ] || DNS=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/dns.py' 2>/dev/null | head -1)
[ -f "$DNS" ] || { echo "tencentcloud-dns script not found (SKILL_DIR=$SKILL_DIR)" >&2; exit 1; }

python3 $DNS domains                                       # list domains
python3 $DNS list example.com                              # records on one domain
python3 $DNS list example.com --type CNAME                 # filter by type
python3 $DNS search example.com --keyword api              # client-side keyword search
python3 $DNS create example.com --sub www --type A --value 1.2.3.4
python3 $DNS create example.com --sub @ --type MX --value 'mail.example.com.' --mx 10
python3 $DNS create example.com --sub _acme-challenge --type TXT --value '"<token>"'
python3 $DNS update example.com <record-id> --sub www --type A --value 5.6.7.8
python3 $DNS delete example.com <record-id> --yes          # destructive, requires --yes

delete 子命令需要 --yes — 不加此参数时,它会打印一行试运行信息,以便你先确认 record-id 是否正确。

适用场景

  • 添加新的子域名(A / AAAA / CNAME)
  • 更新现有记录(更改 IP、更改 CNAME 目标)
  • 添加电子邮件相关记录(MX、SPF / DKIM / DMARC TXT)
  • 添加域名验证 TXT 记录(Google / Search Console / SSL ACME 挑战)
  • 列出或搜索域名上的记录
  • 删除过期记录

依赖项

pip install tencentcloud-sdk-python

快速开始

import os
from tencentcloud.common import credential
from tencentcloud.dnspod.v20210323 import dnspod_client, models

cred = credential.EnvironmentVariableCredential().get_credential()
# DNSPod is global — region is ignored, but the SDK still requires one.
client = dnspod_client.DnspodClient(cred, "")

工作流

列出账户中的域名
req = models.DescribeDomainListRequest()
req.Limit = 100
resp = client.DescribeDomainList(req)
for d in resp.DomainList:
    print(d.DomainId, d.Name, d.Status, d.RecordCount)
列出域名的记录
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 100                  # max 3000
# Optional: req.RecordType = "A"
# Optional: req.Subdomain = "api"
resp = client.DescribeRecordList(req)
for r in resp.RecordList:
    print(r.RecordId, r.Name, r.Type, r.Value, "TTL=", r.TTL, "Line=", r.Line)
按关键词搜索(在客户端筛选)
req = models.DescribeRecordListRequest()
req.Domain = "example.com"
req.Limit = 3000
resp = client.DescribeRecordList(req)
matches = [r for r in resp.RecordList if "api" in r.Name or "api" in r.Value]
for r in matches:
    print(r.RecordId, r.Name, r.Type, r.Value)
创建记录
def create_record(domain, sub_domain, record_type, value, ttl=600, mx=None):
    req = models.CreateRecordRequest()
    req.Domain = domain
    req.SubDomain = sub_domain   # use "@" for the apex
    req.RecordType = record_type
    req.RecordLine = "默认"      # "Default" line — works in all environments
    req.Value = value
    req.TTL = ttl
    if mx is not None:
        req.MX = mx
    resp = client.CreateRecord(req)
    return resp.RecordId

# A record
rid = create_record("example.com", "www", "A", "1.2.3.4")
# CNAME (note: Value MUST end with a dot for absolute target)
rid = create_record("example.com", "api2", "CNAME", "api.example.com.")
# MX (priority via mx=)
rid = create_record("example.com", "@", "MX", "mail.example.com.", mx=10)
# TXT (SPF)
rid = create_record("example.com", "@", "TXT", '"v=spf1 include:_spf.google.com ~all"')
# ACME challenge for cert issuance
rid = create_record("example.com", "_acme-challenge", "TXT", '"<validation-token>"')
更新现有记录
req = models.ModifyRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
req.SubDomain = "www"
req.RecordType = "A"
req.RecordLine = "默认"
req.Value = "5.6.7.8"
req.TTL = 600
client.ModifyRecord(req)
删除记录
# Confirm with the user before running.
req = models.DeleteRecordRequest()
req.Domain = "example.com"
req.RecordId = 123456789
client.DeleteRecord(req)

记录类型

类型用途示例值
AIPv4 地址1.2.3.4
AAAAIPv6 地址2001:db8::1
CNAME指向其他主机名的别名target.example.com.
MX邮件服务器mail.example.com.(设置 MX= 优先级)
TXTSPF / DKIM / DMARC / 域名验证 / ACME"v=spf1 ..."(加引号)
NS委派子区域ns1.example.com.
SRV服务发现0 5 443 api.example.com.
CAA证书颁发机构授权0 issue "letsencrypt.org"

CNAME 顶点域名限制

DNSPod(与所有其他 DNS 服务一样)不支持在顶点域名 @(裸域名)上设置 CNAME,前提是该域名上存在其他类型的记录。顶点域名请使用 A;子域名请使用 CNAME。如果上游本身是主机名(例如 EdgeOne / CDN 终端节点),请通过 EdgeOne 控制台使用 Alias 记录类型 — DNSPod 本身没有 ALIAS 类型。

RecordLine(“线路”)

DNSPod 可以通过 RecordLine 向不同的 ISP / 地区提供不同的值。99% 的情况下,请选择 "默认"(Default)— 它会向所有解析器提供服务。其他常见线路包括:"电信"、"联通"、"移动"、"境外"、"国内"。请使用控制台设置分流 DNS;API 只允许你写入记录。

验证更改

dig @119.29.29.29 www.example.com +short    # 119.29.29.29 = DNSPod's recursor
dig www.example.com +trace                  # follow the delegation chain

DNSPod 自身解析器上的传播通常不到一分钟,其他地方则受 TTL 限制。迭代期间请使用 TTL=60;稳定后将其调高至 600。

重要提醒

  • CNAME 值需要以句点结尾,才能表示绝对域名(api.example.com.)。如果不加,DNSPod 不会拒绝 — 但解析器会很难处理。
  • 删除前请与用户确认 — 删除后无法撤销。需要提供 RecordId,因此请先搜索确认。
  • 不要轻易轮换 NS 记录 — 丢失名称服务器委派会导致整个域名离线,直到你修复为止。
  • **SPF / DMARC 的 TXT 值每个分块必须少于 255 个字符。**对于较长的策略,请在一个 TXT 值中拆分为多个带引号的字符串。
  • DNSPod 的免费 / 付费套餐对 RecordCount 和 RecordsPerMinute 分别设有配额。如果出现 LimitExceeded 错误,请检查控制台。

控制台链接

评论

支持 Markdown