Skip to main content

automatically update DNS records to dynamic local IP [自动更新DNS记录指向本地IP]

Project description

DDNS

自动更新 DNS 解析 到本机 IP 地址,支持 ipv4 和 ipv6 以 本地(内网)IP 和 公网 IP。 代理模式,支持自动创建域名记录。

PyPI Build Status Build Status latest deploy

Build Details
  • Linux Python (2 和 3): Travis build
  • Windows Python3.7: Build Status
  • Windows Python2.7: Build Status
  • Mac OSX Python3.7: Build Status
  • Mac OSX Python2.7: Build Status

Features

  • 兼容和跨平台:
    • 可执行文件(无需 python 环境)
    • 多系统兼容 cross platform
    • python2 和 python3 支持 PyPI - Python Version
    • PIP 安装 PyPI - Wheel
  • 域名支持:
    • 多个域名支持
    • 多级域名解析
    • 自动创建新记录
  • IP 类型:
    • 内网 IPv4 / IPv6
    • 公网 IPv4 / IPv6 (支持自定义 API)
    • 自定义命令(shell)
    • 正则选取支持(@rufengsuixing)
  • 网络代理:
    • http 代理支持
    • 多代理自动切换
  • 服务商支持:
  • 其他:
    • 可设置定时任务
    • 本地文件缓存(减少 API 请求)

使用

① 安装

根据需要选择一种方式: 二进制版,pip版,或者源码运行

  • pip 安装(需要 pip 或 easy_install)

    1. 安装 ddns: pip install ddnseasy_install ddns
    2. 运行: ddns
  • 二进制版(单文件,无需 python)

  • 源码运行(无任何依赖, 需 python 环境)

    1. clone 或者下载此仓库并解压
    2. 运行./run.py (widnows 双击run.bat或者运行python run.py)

② 快速配置

  1. 申请 api token,填写到对应的idtoken字段:

  2. 修改配置文件,ipv4ipv6字段,为待更新的域名,详细参照配置说明

详细配置

config.json 配置文件
  • 首次运行会自动生成一个模板配置文件
  • 可以使用 -c使用指定的配置文件 (默认读取当前目录的 config.json)
  • 推荐使用 vscode 等支持 JsonSchema 的编辑器编辑配置文件
ddns -c path/to/config.json
# 或者源码运行
python run.py -c /path/to/config.json

配置参数表

key type required default description tips
id string api 访问 ID cloudflare 为邮箱
token string api 授权 token 也叫 secret key, 反馈粘贴时删除
dns string No "dnspod" dns 服务商 阿里alidns,
dns.com 为dnscom,
DNSPOD 国际版dnspod_com
ipv4 array No [] ipv4 域名列表 []时,不会获取和更新 IPv4 地址
ipv6 array No [] ipv6 域名列表 []时,不会获取和更新 IPv6 地址
index4 string|int No "default" ipv4 获取方式 可设置网卡,内网,公网,正则等方式
index6 string|int No "default" ipv6 获取方式 可设置网卡,内网,公网,正则等方式
proxy string No http 代理;分割 多代理逐个尝试直到成功,DIRECT为直连
debug bool No false 是否开启调试 运行异常时,打开调试输出,方便诊断错误
cache bool No true 是否缓存记录 正常情况打开避免频繁更新

index4 和 index6 参数说明

  • 数字(0,1,2,3等): 第 i 个网卡 ip
  • 字符串"default"(或者无此项): 系统访问外网默认 IP
  • 字符串"public": 使用公网 ip(使用公网 API 查询,url 的简化模式)
  • 字符串"url:xxx": 打开 URL xxx(如:"url:http://ip.sb"),从返回的数据提取 IP 地址
  • 字符串"regex:xxx" 正则表达(如"regex:192.*"): 提取ifconfig/ipconfig中与之匹配的首个 IP 地址,注意 json 转义(\要写成\\)
    • "192.*"表示 192 开头的所有 ip
    • 如果想匹配10.00.xxxx应该写成"regex:10\\.00\\..\*"("\\"json 转义成\)
  • 字符串"cmd:xxxx": 执行命令xxxx的 stdout 输出结果作为目标 IP
  • 字符串"shell:xxx": 使用系统 shell 运行xxx,并把结果 stdout 作为目标 IP
  • false: 强制禁止更新 ipv4 或 ipv6 的 DNS 解析

配置示例

{
  "$schema": "https://ddns.newfuture.cc/schema/v2.json",
  "id": "12345",
  "token": "mytokenkey",
  "dns": "dnspod 或 dnspod_com 或 alidns 或 dnscom 或 cloudflare",
  "ipv4": ["ddns.newfuture.cc", "ipv4.ddns.newfuture.cc"],
  "ipv6": ["ddns.newfuture.cc", "ipv6.ddns.newfuture.cc"],
  "index4": 0,
  "index6": "public",
  "proxy": "127.0.0.1:1080;DIRECT",
  "debug": false
}

定时任务

可以通过脚本设置定时任务(默认每5分钟检查一次ip,自动更新)

windows

  • [推荐]以系统身份运行,右键"以管理员身份运行"task.bat(或者在管理员命令行中运行)
  • 以当前用户身份运行定时任务,双击或者运行task.bat (执行时会闪黑框)

linux

运行 sudo ./task.sh

FAQ

Windows Server [SSL: CERTIFICATE_VERIFY_FAILED]

Windows Server 默认安全策略会禁止任何未添加的信任 ssl 证书,可手动添加一下对应的证书 #56

使用系统自带的 IE 浏览器访问一次对应的 API 即可

问题排查反馈
  1. 先确认排查是否是系统/网络环境问题
  2. issues中搜索是否有类似问题
  3. 前两者均无法解决或者确定是 bug,在此新建 issue
    • 开启 debug 配置
    • 附上这些内容 运行版本和方式,系统环境, 出错日志,去掉 id/token的配置文件
    • 源码运行注明使用的 python 环境

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddns-2.7.2.tar.gz (17.8 kB view hashes)

Uploaded Source

Built Distribution

ddns-2.7.2-py2.py3-none-any.whl (20.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page