From 5a95c53055eba6ae20bdba44b2eee09211451433 Mon Sep 17 00:00:00 2001 From: ProfFan Date: Sun, 26 Jul 2015 22:59:38 +0800 Subject: [PATCH 1/7] Update ddnspod.sh --- ddnspod.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ddnspod.sh b/ddnspod.sh index fc87d0c..a7a2aeb 100644 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -14,14 +14,12 @@ arPass=arMail="" # 获得外网地址 arIpAdress() { - local inter="http://members.3322.org/dyndns/getip" - wget --quiet --output-document=- $inter + ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 } # 查询域名地址 # 参数: 待查询域名 arNslookup() { - local inter="http://119.29.29.29/d?dn=" wget --quiet --output-document=- $inter$1 } @@ -37,7 +35,7 @@ arApiPost() { # 更新记录信息 # 参数: 主域名 子域名 arDdnsUpdate() { - local domainID recordID recordRS recordCD + local domainID recordID recordRS recordCD myIP # 获得域名ID domainID=$(arApiPost "Domain.Info" "domain=${1}") domainID=$(echo $domainID | sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/') @@ -45,7 +43,8 @@ arDdnsUpdate() { recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}") recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/') # 更新记录IP - recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_line=默认") + myIP=$(arNslookup) + recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/') # 输出记录IP if [ "$recordCD" == "1" ]; then From 882e441909a2fdf802fe93243eb04a25aff4dd85 Mon Sep 17 00:00:00 2001 From: ProfFan Date: Sun, 26 Jul 2015 23:00:44 +0800 Subject: [PATCH 2/7] Update ddnspod.sh --- ddnspod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddnspod.sh b/ddnspod.sh index a7a2aeb..c666f48 100644 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -43,7 +43,7 @@ arDdnsUpdate() { recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}") recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/') # 更新记录IP - myIP=$(arNslookup) + myIP=$(arIpAdress) recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/') # 输出记录IP From 8edcd8db59c9575be27e7abb211755b10b9d252a Mon Sep 17 00:00:00 2001 From: ProfFan Date: Fri, 23 Oct 2015 19:06:56 +0800 Subject: [PATCH 3/7] Update ddnspod.sh --- ddnspod.sh | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/ddnspod.sh b/ddnspod.sh index c666f48..88d216c 100644 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -3,28 +3,26 @@ ################################################# # AnripDdns v5.07.07 -# 基于DNSPod用户API实现的动态域名客户端 -# 作者: 若海[mail@anrip.com] -# 介绍: http://www.anrip.com/ddnspod -# 时间: 2015-07-07 10:25:00 +# Dynamic DNS using DNSPod API +# Edited by ProfFan ################################################# -# 全局变量表 +# Global Variables arPass=arMail="" -# 获得外网地址 +# Port IP arIpAdress() { ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 } -# 查询域名地址 -# 参数: 待查询域名 +# Get Domain IP +# arg: domain arNslookup() { wget --quiet --output-document=- $inter$1 } -# 读取接口数据 -# 参数: 接口类型 待提交数据 +# Get data +# arg: type data arApiPost() { local agent="AnripDdns/5.07(mail@anrip.com)" local inter="https://dnsapi.cn/${1:?'Info.Version'}" @@ -32,31 +30,31 @@ arApiPost() { wget --quiet --no-check-certificate --output-document=- --user-agent=$agent --post-data $param $inter } -# 更新记录信息 -# 参数: 主域名 子域名 +# Update +# arg: main domain sub domain arDdnsUpdate() { local domainID recordID recordRS recordCD myIP - # 获得域名ID + # Get domain ID domainID=$(arApiPost "Domain.Info" "domain=${1}") domainID=$(echo $domainID | sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/') - # 获得记录ID + # Get Record ID recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}") recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/') - # 更新记录IP + # Update IP myIP=$(arIpAdress) recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/') - # 输出记录IP + # Output IP if [ "$recordCD" == "1" ]; then echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/' return 1 fi - # 输出错误信息 + # Echo error message echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/' } -# 动态检查更新 -# 参数: 主域名 子域名 +# DDNS Check +# Arg: Main Sub arDdnsCheck() { local postRS local hostIP=$(arIpAdress) @@ -75,10 +73,10 @@ arDdnsCheck() { ################################################### -# 设置用户参数 +# User arMail="user@anrip.com" arPass="anrip.net" -# 检查更新域名 +# DDNS arDdnsCheck "anrip.com" "lab" arDdnsCheck "anrip.net" "lab" From e2062becd20d06f48bba63e8dd74fa78b16bacf4 Mon Sep 17 00:00:00 2001 From: ProfFan Date: Sat, 24 Oct 2015 18:49:15 +0800 Subject: [PATCH 4/7] Fixed a typo --- ddnspod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddnspod.sh b/ddnspod.sh index 88d216c..7935b67 100644 --- a/ddnspod.sh +++ b/ddnspod.sh @@ -45,7 +45,7 @@ arDdnsUpdate() { recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/') # Output IP - if [ "$recordCD" == "1" ]; then + if [ "$recordCD" = "1" ]; then echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/' return 1 fi From 6cb5bacbdcee871304caf743f4872f34bb5f01ef Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Thu, 25 Feb 2016 17:48:20 +0800 Subject: [PATCH 5/7] Updated script --- .gitignore | 2 ++ ddnspod.sh | 23 +++++++++++++++-------- dns.conf.example | 5 +++++ 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 ddnspod.sh create mode 100644 dns.conf.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1e2a42d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dns.conf + diff --git a/ddnspod.sh b/ddnspod.sh old mode 100644 new mode 100755 index 7935b67..50c85ae --- a/ddnspod.sh +++ b/ddnspod.sh @@ -1,4 +1,3 @@ - #!/bin/sh ################################################# @@ -7,12 +6,16 @@ # Edited by ProfFan ################################################# +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source $DIR/dns.conf + # Global Variables -arPass=arMail="" +# arPass=arMail="" # Port IP arIpAdress() { - ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1 + ipconfig getifaddr en6 } # Get Domain IP @@ -37,13 +40,16 @@ arDdnsUpdate() { # Get domain ID domainID=$(arApiPost "Domain.Info" "domain=${1}") domainID=$(echo $domainID | sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/') + # Get Record ID recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}") recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/') + # Update IP myIP=$(arIpAdress) - recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") + recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认") recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/') + # Output IP if [ "$recordCD" = "1" ]; then echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/' @@ -74,9 +80,10 @@ arDdnsCheck() { ################################################### # User -arMail="user@anrip.com" -arPass="anrip.net" # DDNS -arDdnsCheck "anrip.com" "lab" -arDdnsCheck "anrip.net" "lab" +echo ${#domains[@]} +for index in ${!domains[@]}; do + echo "${domains[index]} ${subdomains[index]}" + arDdnsCheck "${domains[index]}" "${subdomains[index]}" +done \ No newline at end of file diff --git a/dns.conf.example b/dns.conf.example new file mode 100644 index 0000000..6d56b84 --- /dev/null +++ b/dns.conf.example @@ -0,0 +1,5 @@ +arMail="test@gmail.com" +arPass="test" + +declare -a domains=("test.net") +declare -a subdomains=("abc") From ea4f75ce27b9ab63f0724ca54b966803e3f70408 Mon Sep 17 00:00:00 2001 From: Fan Jiang Date: Thu, 25 Feb 2016 17:55:31 +0800 Subject: [PATCH 6/7] Updated README --- README.md | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index eeeeebe..6600034 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,19 @@ # ArDNSPod + 基于DNSPod用户API实现的纯Shell动态域名客户端 -2015年7月7日 -- 使用D+服务获取域名解析 +# 最近更新 -2013年8月9日 -- 修正一处笔误 +增加配置文件,分离脚本与配置,适配内网。 -2013年8月8日 -- 默认DNS查询服务器更换为114.114.114.114 +# Issue -2013年5月23日 -- [[]]替换为[],防止一些嵌入设备无此命令 +- [ ] Mac下sed需要使用gnu sed +- [ ] 增加外网支持 +- [ ] 自动检测环境,Mac使用ipconfig,Linux使用ip -2013年4月1日 -- 完善说明文档 -- 优化全局变量定义 -- 刚发现DnsPod官方API示例已收录本文 +# Credit -2013年3月29日 -- 从dns服务器获取子域名IP -- 实现仅IP变更后才提交更新 +Original: anrip -2013年3月28日 -- 现在是13年3月,故而第一个版本就定为v3.3吧 -- 使用APIv4.6实现简单的动态更新功能 +This version maintained by ProfFan From c8b2c35a591f8bca3cded9d6c96f6f1ea769d99b Mon Sep 17 00:00:00 2001 From: ProfFan Date: Thu, 25 Feb 2016 20:28:32 +0800 Subject: [PATCH 7/7] Update README.md --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a5ce27b..bb38074 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,25 @@ # ArDNSPod -基于DNSPod用户API实现的纯Shell动态域名客户端 +基于DNSPod用户API实现的纯Shell动态域名客户端,适配网卡地址。 # 最近更新 -======= -2015/2/24 +2015/2/24 - 增加token鉴权方式 (by wbchn) 2015/7/7 - - 使用D+服务获取域名解析 2016/2/25 - - 增加配置文件,分离脚本与配置,适配内网。 - 加入Mac支持 - sed脚本POSIX化,可跨平台 # Issue -- [*] Mac下sed需要使用gnu sed +- [x] Mac下sed需要使用gnu sed - [ ] 增加外网支持 -- [*] 自动检测环境,Mac使用ipconfig,Linux使用ip +- [x] 自动检测环境,Mac使用ipconfig,Linux使用ip # Credit