一个用于DNSPod DNS记录智能同步的Python脚本,支持多线路智能解析拉平。
本项目基于 KincaidYang/CNAMEFlattening 二次开发,针对云原生构建场景进行了优化。
本工具默认设计用于 云原生构建 环境,通过 .cnb.yml 配置文件使用:
main:
"crontab: */20 * * * *":
- stages:
- name: sync dns records
image: docker.cnb.cool/bring/tools/flatteningdns:latest
imports:
- https://cnb.cool/$CNB_SLUG/secret/-/blob/main/TencentCloud.yml
settings:
domain: example.com
subdomain: "@"
cname: target.example.com
secret-id: ${TENCENTCLOUD_SECRET_ID}
secret-key: ${TENCENTCLOUD_SECRET_KEY}
type: both
threads: 20
pip install tencentcloud-sdk-python requests
python main.py \
--domain "example.com" \
--subdomain "@" \
--cname "target.example.com" \
--secret-id "your-secret-id" \
--secret-key "your-secret-key"
export PLUGIN_DOMAIN="example.com"
export PLUGIN_SUBDOMAIN="@"
export PLUGIN_CNAME="target.example.com"
export PLUGIN_SECRET_ID="your-secret-id"
export PLUGIN_SECRET_KEY="your-secret-key"
python main.py
docker run --rm \
-e PLUGIN_DOMAIN="example.com" \
-e PLUGIN_SUBDOMAIN="@" \
-e PLUGIN_CNAME="target.example.com" \
-e PLUGIN_SECRET_ID="your-secret-id" \
-e PLUGIN_SECRET_KEY="your-secret-key" \
docker.cnb.cool/bring/tools/flatteningdns:latest
参数优先级:命令行参数 > PLUGIN_环境变量 > 默认值
| 参数 | CLI参数 | 环境变量 | 默认值 | 说明 |
|---|---|---|---|---|
| 主域名 | --domain | PLUGIN_DOMAIN | - | 必填,如:example.com |
| 子域名 | --subdomain | PLUGIN_SUBDOMAIN | - | 必填,如:@ 或 www |
| 目标CNAME | --cname | PLUGIN_CNAME | - | 必填,目标域名 |
| SecretId | --secret-id | PLUGIN_SECRET_ID | - | 腾讯云SecretId |
| SecretKey | --secret-key | PLUGIN_SECRET_KEY | - | 腾讯云SecretKey |
| Token | --token | PLUGIN_TOKEN | - | 可选,STS临时凭证 |
| DoH地址 | --doh-url | PLUGIN_DOH_URL | https://doh.pub/dns-query | DoH查询地址 |
| 线程数 | --threads | PLUGIN_THREADS | 20 | 并发线程数 |
| 同步类型 | --type | PLUGIN_TYPE | both | A/AAAA/both |
| 默认线路 | --default-lines | PLUGIN_DEFAULT_LINES | 上海电信,北京联通,广东移动 | 默认负载线路 |
脚本内置了全国各省市运营商的DNS线路:
🚀 同步 A 记录中... 🗑️ 删除 A 北京联通: 123456 🔄 更新 A 上海电信: 192.168.1.1 ➕ 添加 A 广东移动: 192.168.1.2 ✅ A 同步完成,共 45 条有效线路 🚀 同步 AAAA 记录中... ➕ 添加 AAAA 北京电信: 2001:db8::1 ✅ AAAA 同步完成,共 12 条有效线路 🏁 全部同步完成,用时 15 秒