{"id":13512276,"url":"https://github.com/NewFuture/DDNS","last_synced_at":"2025-03-30T22:32:25.976Z","repository":{"id":37493368,"uuid":"60844169","full_name":"NewFuture/DDNS","owner":"NewFuture","description":":triangular_flag_on_post: 自动更新域名解析到本机IP(支持dnspod,阿里DNS,CloudFlare,华为云,DNSCOM...)","archived":false,"fork":false,"pushed_at":"2024-09-11T03:29:01.000Z","size":342,"stargazers_count":4456,"open_issues_count":56,"forks_count":677,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-03-25T20:17:17.640Z","etag":null,"topics":["alidns","cloudflare","ddns","dns","dnscom","dnspod","ipv4","ipv6"],"latest_commit_sha":null,"homepage":"https://ddns.newfuture.cc/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NewFuture.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-10T11:51:51.000Z","updated_at":"2025-03-25T14:40:53.000Z","dependencies_parsed_at":"2023-01-24T18:05:07.380Z","dependency_job_id":"8dd75937-8374-42ff-9eb8-6c4a1a794d35","html_url":"https://github.com/NewFuture/DDNS","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2FDDNS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2FDDNS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2FDDNS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewFuture%2FDDNS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewFuture","download_url":"https://codeload.github.com/NewFuture/DDNS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246390883,"owners_count":20769475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alidns","cloudflare","ddns","dns","dnscom","dnspod","ipv4","ipv6"],"created_at":"2024-08-01T03:01:40.678Z","updated_at":"2025-03-30T22:32:22.089Z","avatar_url":"https://github.com/NewFuture.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# [DDNS](https://github.com/NewFuture/DDNS)\n\n\u003e 自动更新 DNS 解析 到本机 IP 地址,支持 ipv4 和 ipv6 以 本地(内网)IP 和 公网 IP。\n\u003e 代理模式,支持自动创建域名记录。\n\n[![PyPI](https://img.shields.io/pypi/v/ddns.svg?label=DDNS\u0026style=social)](https://pypi.org/project/ddns/)\n[![Build Status](https://github.com/NewFuture/DDNS/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/NewFuture/DDNS/actions/workflows/build.yml)\n[![Publish Status](https://github.com/NewFuture/DDNS/actions/workflows/publish.yml/badge.svg)](https://github.com/NewFuture/DDNS/releases/latest)\n\n---\n\n## Features\n\n- 兼容和跨平台:\n  - [x] 可执行文件(无需 python 环境)\n  - [x] 多系统兼容 ![cross platform](https://img.shields.io/badge/platform-windows_%7C%20linux_%7C%20osx-success.svg?style=social)\n  - [x] python3 支持 ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ddns.svg?style=social)(2.x支持python2和python3)\n  - [x] PIP 安装 ![PyPI - Wheel](https://img.shields.io/pypi/wheel/ddns.svg?style=social)\n  - [x] Docker 支持(@NN708)\n- 域名支持:\n  - [x] 多个域名支持\n  - [x] 多级域名解析\n  - [x] 自动创建新记录\n- IP 类型:\n  - [x] 内网 IPv4 / IPv6\n  - [x] 公网 IPv4 / IPv6 (支持自定义 API)\n  - [x] 自定义命令(shell)\n  - [x] 正则选取支持(@rufengsuixing)\n- 网络代理:\n  - [x] http 代理支持\n  - [x] 多代理自动切换\n- 服务商支持:\n  - [x] [DNSPOD](https://www.dnspod.cn/)\n  - [x] [阿里 DNS](http://www.alidns.com/)\n  - [x] [DNS.COM](https://www.dns.com/)(@loftor-git)\n  - [x] [DNSPOD 国际版](https://www.dnspod.com/)\n  - [x] [CloudFlare](https://www.cloudflare.com/)(@tongyifan)\n  - [x] [HE.net](https://dns.he.net/)(@NN708) (不支持自动创建记录)\n  - [x] [华为云](https://huaweicloud.com/)(@cybmp3)\n- 其他:\n  - [x] 可设置定时任务\n  - [x] TTL 配置支持\n  - [x] 本地文件缓存(减少 API 请求)\n  - [x] 地址变更时触发自定义回调API(与 DDNS 功能互斥)\n\n## 使用\n\n### ① 安装\n\n根据需要选择一种方式: `二进制`版,`pip`版,`源码`运行,或者`Docker`\n\n- #### pip 安装(需要 pip 或 easy_install)\n  1. 安装 ddns: `pip install ddns` 或 `easy_install ddns`\n  2. 运行: `ddns`\n- #### 二进制版(单文件,无需 python)\n  - Windows [ddns.exe](https://github.com/NewFuture/DDNS/releases/latest)\n  - Linux (仅 Ubuntu 测试) [ddns](https://github.com/NewFuture/DDNS/releases/latest)\n  - Mac OSX [ddns-osx](https://github.com/NewFuture/DDNS/releases/latest)\n- #### 源码运行(无任何依赖, 需 python 环境)\n  1. clone 或者[下载此仓库](https://github.com/NewFuture/DDNS/archive/master.zip)并解压\n  2. 运行./run.py (widnows 双击`run.bat`或者运行`python run.py`)\n- #### Docker(需要安装 Docker)\n  - 使用环境变量：\n    ```\n    docker run -d \\\n      -e DDNS_DNS=dnspod \\\n      -e DDNS_ID=12345 \\\n      -e DDNS_TOKEN=mytokenkey \\\n      -e DDNS_IPV4=ddns.newfuture.cc \\\n      -e DDNS_IPV6=ddns.newfuture.cc \\\n      --network host \\\n      newfuture/ddns\n    ```\n  - 使用配置文件：\n    ```\n    docker run -d \\\n      -v /path/to/config.json:/config.json \\\n      --network host \\\n      newfuture/ddns\n    ```\n\n### ② 快速配置\n\n1. 申请 api `token`,填写到对应的`id`和`token`字段:\n\n   - [DNSPOD(国内版)创建 token](https://support.dnspod.cn/Kb/showarticle/tsid/227/)\n   - [阿里云 accesskey](https://help.aliyun.com/document_detail/87745.htm)\n   - [DNS.COM API Key/Secret](https://www.dns.com/member/apiSet)\n   - [DNSPOD(国际版)](https://www.dnspod.com/docs/info.html#get-the-user-token)\n   - [CloudFlare API Key](https://support.cloudflare.com/hc/en-us/articles/200167836-Where-do-I-find-my-Cloudflare-API-key-) (除了`email + API KEY`,也可使用`Token`需要列出 Zone 权限)\n   - [HE.net DDNS 文档](https://dns.he.net/docs.html)（仅需将设置的密码填入`token`字段，`id`字段可留空）\n   - [华为 APIKEY 申请](https://console.huaweicloud.com/iam/)（点左边访问密钥，然后点新增访问密钥）\n   - 自定义回调的参数填写方式请查看下方的自定义回调配置说明\n\n2. 修改配置文件,`ipv4`和`ipv6`字段，为待更新的域名,详细参照配置说明\n\n## 详细配置\n\n所有字段可通过三种方式进行配置\n\n1. 命令行参数 `ddns --key=value` (`ddns -h` 查看详情)，优先级最高\n2. JSON配置文件(值为null认为是有效值，会覆盖环境变量的设置，如果没有对应的key则会尝试试用环境变量)\n3. 环境变量DDNS_前缀加上key 全大写或者全小写 (`${ddns_key}` 或 `${DDNS_KEY}`)\n\n\u003cdetails open\u003e\n\n\u003csummary markdown=\"span\"\u003econfig.json 配置文件\n\u003c/summary\u003e\n\n- 首次运行会自动生成一个模板配置文件\n- 可以使用 `-c`使用指定的配置文件 (默认读取当前目录的 config.json)\n- 推荐使用 vscode 等支持 JsonSchema 的编辑器编辑配置文件\n\n```bash\nddns -c path/to/config.json\n# 或者源码运行\npython run.py -c /path/to/config.json\n```\n\n#### 配置参数表\n\n|  key   |        type        | required |   default   |    description    | tips                                                                                                        |\n| :----: | :----------------: | :------: | :---------: | :---------------: | ----------------------------------------------------------------------------------------------------------- |\n|   id   |       string       |    √     |     无      |    api 访问 ID    | Cloudflare 为邮箱(使用 Token 时留空)\u003cbr\u003eHE.net 可留空\u003cbr\u003e华为云为 Access Key ID (AK)                                                       |\n| token  |       string       |    √     |     无      |  api 授权 token   | 部分平台叫 secret key , **反馈粘贴时删除**                                                                  |\n|  dns   |       string       |    No    | `\"dnspod\"`  |    dns 服务商     | 阿里 DNS 为`alidns`,\u003cbr\u003eCloudflare 为 `cloudflare`,\u003cbr\u003edns.com 为 `dnscom`,\u003cbr\u003eDNSPOD 国内为 `dnspod`,\u003cbr\u003eDNSPOD 国际版为 `dnspod_com`,\u003cbr\u003eHE.net 为`he`,\u003cbr\u003e华为 DNS 为`huaweidns`,\u003cbr\u003e自定义回调为`callback` |\n|  ipv4  |       array        |    No    |    `[]`     |   ipv4 域名列表   | 为`[]`时,不会获取和更新 IPv4 地址                                                                           |\n|  ipv6  |       array        |    No    |    `[]`     |   ipv6 域名列表   | 为`[]`时,不会获取和更新 IPv6 地址                                                                           |\n| index4 | string\\|int\\|array |    No    | `\"default\"` |   ipv4 获取方式   | 可设置`网卡`,`内网`,`公网`,`正则`等方式                                                                     |\n| index6 | string\\|int\\|array |    No    | `\"default\"` |   ipv6 获取方式   | 可设置`网卡`,`内网`,`公网`,`正则`等方式                                                                     |\n|  ttl   |       number       |    No    |   `null`    | DNS 解析 TTL 时间 | 不设置采用 DNS 默认策略                                                                                     |\n| proxy  |       string       |    No    |     无      | http 代理`;`分割  | 多代理逐个尝试直到成功,`DIRECT`为直连                                                                       |\n| debug  |        bool        |    No    |   `false`   |   是否开启调试    | 运行异常时,打开调试输出,方便诊断错误                                                                        |\n| cache  |    string\\|bool    |    No    |   `true`    |   是否缓存记录    | 正常情况打开避免频繁更新,默认位置为临时目录下`ddns.cache`,\u003cbr\u003e也可以指定一个具体文件实现自定义文件缓存位置         |\n\n#### index4 和 index6 参数说明\n\n- 数字(`0`,`1`,`2`,`3`等): 第 i 个网卡 ip\n- 字符串`\"default\"`(或者无此项): 系统访问外网默认 IP\n- 字符串`\"public\"`: 使用公网 ip(使用公网 API 查询,url 的简化模式)\n- 字符串`\"url:xxx\"`: 打开 URL `xxx`(如:`\"url:http://ip.sb\"`),从返回的数据提取 IP 地址\n- 字符串`\"regex:xxx\"` 正则表达(如`\"regex:192.*\"`): 提取`ifconfig`/`ipconfig`中与之匹配的首个 IP 地址,**注意 json 转义**(`\\`要写成`\\\\`)\n  - `\"192.*\"`表示 192 开头的所有 ip\n  - 如果想匹配`10.00.xxxx`应该写成`\"regex:10\\\\.00\\\\..\\*\"`(`\"\\\\\"`json 转义成`\\`)\n- 字符串`\"cmd:xxxx\"`: 执行命令`xxxx`的 stdout 输出结果作为目标 IP\n- 字符串`\"shell:xxx\"`: 使用系统 shell 运行`xxx`,并把结果 stdout 作为目标 IP\n- `false`: 强制禁止更新 ipv4 或 ipv6 的 DNS 解析\n- 列表：依次执行列表中的index规则，并将最先获得的结果作为目标 IP\n  - 例如`[\"public\", \"172.*\"]`将先查询公网API，未获取到IP后再从本地寻找172开头的IP\n\n#### 自定义回调配置说明\n\n- `id` 字段填写回调地址，以 HTTP 或 HTTPS 开头，推荐采用 HTTPS 方式的回调 API ，当 `token` 字段非空且 URL 参数包含下表所示的常量字符串时，常量会被程序替换为实际值\n- `token` 字段为 POST 参数，本字段为空或不存在则使用 GET 方式发起回调，回调参数采用 JSON 格式编码，当 JSON 的首层参数值包含下表所示的常量字符串时，常量会被程序替换为实际值\n\n| 常量名称          | 常量内容               | 说明      |\n| ---------------- | ---------------------- | -------- |\n| `__DOMAIN__`     | DDNS 域名              |          |\n| `__RECORDTYPE__` | DDNS 记录类型           |          |\n| `__TTL__`        | DDNS TTL               |          |\n| `__TIMESTAMP__`  | 请求发起时间戳          | 包含小数 |\n| `__IP__`         | 获取的对应类型的IP地址   |          |\n\n#### 配置示例\n\n```json\n{\n  \"$schema\": \"https://ddns.newfuture.cc/schema/v2.8.json\",\n  \"id\": \"12345\",\n  \"token\": \"mytokenkey\",\n  \"dns\": \"dnspod 或 dnspod_com 或 alidns 或 dnscom 或 cloudflare 或 he 或 huaweidns 或 callback\",\n  \"ipv4\": [\"ddns.newfuture.cc\", \"ipv4.ddns.newfuture.cc\"],\n  \"ipv6\": [\"ddns.newfuture.cc\", \"ipv6.ddns.newfuture.cc\"],\n  \"index4\": 0,\n  \"index6\": \"public\",\n  \"ttl\": 600,\n  \"proxy\": \"127.0.0.1:1080;DIRECT\",\n  \"debug\": false\n}\n```\n\n\u003c/details\u003e\n\n## 定时任务\n\n\u003cdetails\u003e\n\n\u003csummary markdown=\"span\"\u003e可以通过脚本设置定时任务(默认每5分钟检查一次ip,自动更新)\n\u003c/summary\u003e\n\n#### Windows\n\n- [推荐]以系统身份运行,右键\"以管理员身份运行\"`task.bat`(或者在管理员命令行中运行)\n- 以当前用户身份运行定时任务,双击或者运行`task.bat` (执行时会闪黑框)\n\n#### Linux\n\n- 使用init.d和crontab:\n`sudo ./task.sh`\n- 使用systemd:\n    ```bash\n    安装:\n    sudo ./systemd.sh install\n    卸载:\n    sudo ./systemd.sh uninstall\n    ```\n  该脚本安装的文件符合 [Filesystem Hierarchy Standard (FHS)](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard)：\n  可执行文件所在目录为 `/usr/share/DDNS`\n  配置文件所在目录为 `/etc/DDNS`\n\n#### Docker\n\nDocker镜像在无额外参数的情况下，已默认启用每5分钟执行一次的定时任务\n\u003c/details\u003e\n\n## FAQ\n\n\u003cdetails\u003e\n\n\u003csummary markdown=\"span\"\u003e Windows Server [SSL: CERTIFICATE_VERIFY_FAILED]\n\u003c/summary\u003e\n\n\u003e Windows Server 默认安全策略会禁止任何未添加的信任 ssl 证书,可手动添加一下对应的证书 [#56](https://github.com/NewFuture/DDNS/issues/56#issuecomment-487371078)\n\n使用系统自带的 IE 浏览器访问一次对应的 API 即可\n\n- alidns 打开: \u003chttps://alidns.aliyuncs.com\u003e\n- cloudflare 打开: \u003chttps://api.cloudflare.com\u003e\n- dns.com 打开: \u003chttps://www.dns.com\u003e\n- dnspod.cn 打开: \u003chttps://dnsapi.cn\u003e\n- dnspod 国际版: \u003chttps://api.dnspod.com\u003e\n- 华为 DNS \u003chttps://dns.myhuaweicloud.com\u003e\n  \u003c/details\u003e\n\n\u003cdetails\u003e\n\n\u003csummary markdown=\"span\"\u003e 问题排查反馈\n\u003c/summary\u003e\n\n1. 先确认排查是否是系统/网络环境问题\n2. 在[issues](https://github.com/NewFuture/DDNS/issues)中搜索是否有类似问题\n3. 前两者均无法解决或者确定是 bug,[在此新建 issue](https://github.com/NewFuture/DDNS/issues/new)\n   - [ ] 开启 debug 配置\n   - [ ] 附上这些内容 **运行版本和方式**,**系统环境**, **出错日志**,**去掉 id/token**的配置文件\n   - [ ] 源码运行注明使用的 python 环境\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewFuture%2FDDNS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNewFuture%2FDDNS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewFuture%2FDDNS/lists"}