Fixed Mac and Linux compatibility and merged upstream.
Merge branch 'master' of https://github.com/anrip/ArDNSPod into anrip-master
This commit is contained in:
commit
252e0a6045
2 files changed
+75
-21
No files matched your search
@@ -3,14 +3,26 @@
|
|||||||
基于DNSPod用户API实现的纯Shell动态域名客户端
|
基于DNSPod用户API实现的纯Shell动态域名客户端
|
||||||
|
|
||||||
# 最近更新
|
# 最近更新
|
||||||
|
=======
|
||||||
|
2015/2/24
|
||||||
|
|
||||||
增加配置文件,分离脚本与配置,适配内网。
|
- 增加token鉴权方式 (by wbchn)
|
||||||
|
|
||||||
|
2015/7/7
|
||||||
|
|
||||||
|
- 使用D+服务获取域名解析
|
||||||
|
|
||||||
|
2016/2/25
|
||||||
|
|
||||||
|
- 增加配置文件,分离脚本与配置,适配内网。
|
||||||
|
- 加入Mac支持
|
||||||
|
- sed脚本POSIX化,可跨平台
|
||||||
|
|
||||||
# Issue
|
# Issue
|
||||||
|
|
||||||
- [ ] Mac下sed需要使用gnu sed
|
- [*] Mac下sed需要使用gnu sed
|
||||||
- [ ] 增加外网支持
|
- [ ] 增加外网支持
|
||||||
- [ ] 自动检测环境,Mac使用ipconfig,Linux使用ip
|
- [*] 自动检测环境,Mac使用ipconfig,Linux使用ip
|
||||||
|
|
||||||
# Credit
|
# Credit
|
||||||
|
|
||||||
|
|||||||
+60
-18
@@ -1,20 +1,62 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# AnripDdns v5.07.07
|
# AnripDdns v5.08
|
||||||
# Dynamic DNS using DNSPod API
|
# Dynamic DNS using DNSPod API
|
||||||
|
# Original by anrip<mail@anrip.com>, http://www.anrip.com/ddnspod
|
||||||
# Edited by ProfFan
|
# Edited by ProfFan
|
||||||
#################################################
|
#################################################
|
||||||
|
|
||||||
|
# OS Detection
|
||||||
|
case $(uname) in
|
||||||
|
'Linux')
|
||||||
|
echo "Linux"
|
||||||
|
arIpAddress() {
|
||||||
|
ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
'FreeBSD')
|
||||||
|
echo 'FreeBSD'
|
||||||
|
exit 100
|
||||||
|
;;
|
||||||
|
'WindowsNT')
|
||||||
|
echo "Windows"
|
||||||
|
exit 100
|
||||||
|
;;
|
||||||
|
'Darwin')
|
||||||
|
echo "Mac"
|
||||||
|
arIpAddress() {
|
||||||
|
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
'SunOS')
|
||||||
|
echo 'Solaris'
|
||||||
|
exit 100
|
||||||
|
;;
|
||||||
|
'AIX')
|
||||||
|
echo 'AIX'
|
||||||
|
exit 100
|
||||||
|
;;
|
||||||
|
*) ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Get script dir
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
# Global Variables:
|
||||||
|
|
||||||
|
# Token-based Authentication
|
||||||
|
arToken=""
|
||||||
|
# Account-based Authentication
|
||||||
|
arMail=""
|
||||||
|
arPass=""
|
||||||
|
|
||||||
|
# Load config
|
||||||
|
|
||||||
source $DIR/dns.conf
|
source $DIR/dns.conf
|
||||||
|
|
||||||
# Global Variables
|
|
||||||
# arPass=arMail=""
|
|
||||||
|
|
||||||
# Port IP
|
# Port IP
|
||||||
arIpAdress() {
|
arIpAddress() {
|
||||||
ipconfig getifaddr en6
|
ipconfig getifaddr en6
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +71,11 @@ arNslookup() {
|
|||||||
arApiPost() {
|
arApiPost() {
|
||||||
local agent="AnripDdns/5.07(mail@anrip.com)"
|
local agent="AnripDdns/5.07(mail@anrip.com)"
|
||||||
local inter="https://dnsapi.cn/${1:?'Info.Version'}"
|
local inter="https://dnsapi.cn/${1:?'Info.Version'}"
|
||||||
local param="login_email=${arMail}&login_password=${arPass}&format=json&${2}"
|
if [ "x${arToken}" = "x" ]; then # undefine token
|
||||||
|
local param="login_email=${arMail}&login_password=${arPass}&format=json&${2}"
|
||||||
|
else
|
||||||
|
local param="login_token=${arToken}&format=json&${2}"
|
||||||
|
fi
|
||||||
wget --quiet --no-check-certificate --output-document=- --user-agent=$agent --post-data $param $inter
|
wget --quiet --no-check-certificate --output-document=- --user-agent=$agent --post-data $param $inter
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,31 +85,31 @@ arDdnsUpdate() {
|
|||||||
local domainID recordID recordRS recordCD myIP
|
local domainID recordID recordRS recordCD myIP
|
||||||
# Get domain ID
|
# Get domain ID
|
||||||
domainID=$(arApiPost "Domain.Info" "domain=${1}")
|
domainID=$(arApiPost "Domain.Info" "domain=${1}")
|
||||||
domainID=$(echo $domainID | sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/')
|
domainID=$(echo $domainID | sed 's/.*{"id":"\([0-9]*\)".*/\1/')
|
||||||
|
|
||||||
# Get Record ID
|
# Get Record ID
|
||||||
recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}")
|
recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}")
|
||||||
recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/')
|
recordID=$(echo $recordID | sed 's/.*\[{"id":"\([0-9]*\)".*/\1/')
|
||||||
|
|
||||||
# Update IP
|
# Update IP
|
||||||
myIP=$(arIpAdress)
|
myIP=$(arIpAddress)
|
||||||
recordRS=$(arApiPost "Record.Ddns" "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/')
|
recordCD=$(echo $recordRS | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
||||||
|
|
||||||
# Output IP
|
# Output IP
|
||||||
if [ "$recordCD" = "1" ]; then
|
if [ "$recordCD" = "1" ]; then
|
||||||
echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/'
|
echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# Echo error message
|
# Echo error message
|
||||||
echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/'
|
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
|
||||||
}
|
}
|
||||||
|
|
||||||
# DDNS Check
|
# DDNS Check
|
||||||
# Arg: Main Sub
|
# Arg: Main Sub
|
||||||
arDdnsCheck() {
|
arDdnsCheck() {
|
||||||
local postRS
|
local postRS
|
||||||
local hostIP=$(arIpAdress)
|
local hostIP=$(arIpAddress)
|
||||||
local lastIP=$(arNslookup "${2}.${1}")
|
local lastIP=$(arNslookup "${2}.${1}")
|
||||||
echo "hostIP: ${hostIP}"
|
echo "hostIP: ${hostIP}"
|
||||||
echo "lastIP: ${lastIP}"
|
echo "lastIP: ${lastIP}"
|
||||||
@@ -77,13 +123,9 @@ arDdnsCheck() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
###################################################
|
|
||||||
|
|
||||||
# User
|
|
||||||
|
|
||||||
# DDNS
|
# DDNS
|
||||||
echo ${#domains[@]}
|
echo ${#domains[@]}
|
||||||
for index in ${!domains[@]}; do
|
for index in ${!domains[@]}; do
|
||||||
echo "${domains[index]} ${subdomains[index]}"
|
echo "${domains[index]} ${subdomains[index]}"
|
||||||
arDdnsCheck "${domains[index]}" "${subdomains[index]}"
|
arDdnsCheck "${domains[index]}" "${subdomains[index]}"
|
||||||
done
|
done
|
||||||
Reference in new issue
Block a user