commit
d567684a58
4 files changed
+107
-60
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
dns.conf
|
||||||
|
|
||||||
@@ -1,30 +1,28 @@
|
|||||||
# ArDNSPod
|
# ArDNSPod
|
||||||
基于DNSPod用户API实现的纯Shell动态域名客户端
|
|
||||||
|
|
||||||
2015年2月24日
|
基于DNSPod用户API实现的纯Shell动态域名客户端,适配网卡地址。
|
||||||
- 增加token权鉴方式 (by wbchn)
|
|
||||||
|
|
||||||
2015年7月7日
|
# 最近更新
|
||||||
|
|
||||||
|
2015/2/24
|
||||||
|
- 增加token鉴权方式 (by wbchn)
|
||||||
|
|
||||||
|
2015/7/7
|
||||||
- 使用D+服务获取域名解析
|
- 使用D+服务获取域名解析
|
||||||
|
|
||||||
2013年8月9日
|
2016/2/25
|
||||||
- 修正一处笔误
|
- 增加配置文件,分离脚本与配置,适配内网。
|
||||||
|
- 加入Mac支持
|
||||||
|
- sed脚本POSIX化,可跨平台
|
||||||
|
|
||||||
2013年8月8日
|
# Issue
|
||||||
- 默认DNS查询服务器更换为114.114.114.114
|
|
||||||
|
|
||||||
2013年5月23日
|
- [x] Mac下sed需要使用gnu sed
|
||||||
- [[]]替换为[],防止一些嵌入设备无此命令
|
- [ ] 增加外网支持
|
||||||
|
- [x] 自动检测环境,Mac使用ipconfig,Linux使用ip
|
||||||
|
|
||||||
2013年4月1日
|
# Credit
|
||||||
- 完善说明文档
|
|
||||||
- 优化全局变量定义
|
|
||||||
- 刚发现DnsPod官方API示例已收录本文
|
|
||||||
|
|
||||||
2013年3月29日
|
Original: anrip
|
||||||
- 从dns服务器获取子域名IP
|
|
||||||
- 实现仅IP变更后才提交更新
|
|
||||||
|
|
||||||
2013年3月28日
|
This version maintained by ProfFan
|
||||||
- 现在是13年3月,故而第一个版本就定为v3.3吧
|
|
||||||
- 使用APIv4.6实现简单的动态更新功能
|
|
||||||
Regular → Executable
+82
-40
@@ -1,35 +1,73 @@
|
|||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# AnripDdns v5.08
|
# AnripDdns v5.08
|
||||||
# 基于DNSPod用户API实现的动态域名客户端
|
# Dynamic DNS using DNSPod API
|
||||||
# 作者: 若海[mail@anrip.com]
|
# Original by anrip<mail@anrip.com>, http://www.anrip.com/ddnspod
|
||||||
# 介绍: http://www.anrip.com/ddnspod
|
# Edited by ProfFan
|
||||||
# 时间: 2016-02-24 16:25:00
|
|
||||||
#################################################
|
#################################################
|
||||||
|
|
||||||
# 使用Token认证(推荐)
|
# 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 )"
|
||||||
|
|
||||||
|
# Global Variables:
|
||||||
|
|
||||||
|
# Token-based Authentication
|
||||||
arToken=""
|
arToken=""
|
||||||
# 使用邮箱和密码认证
|
# Account-based Authentication
|
||||||
arMail=""
|
arMail=""
|
||||||
arPass=""
|
arPass=""
|
||||||
|
|
||||||
# 获得外网地址
|
# Load config
|
||||||
arIpAdress() {
|
|
||||||
local inter="http://members.3322.org/dyndns/getip"
|
source $DIR/dns.conf
|
||||||
wget --quiet --output-document=- $inter
|
|
||||||
|
# Port IP
|
||||||
|
arIpAddress() {
|
||||||
|
ipconfig getifaddr en6
|
||||||
}
|
}
|
||||||
|
|
||||||
# 查询域名地址
|
# Get Domain IP
|
||||||
# 参数: 待查询域名
|
# arg: domain
|
||||||
arNslookup() {
|
arNslookup() {
|
||||||
local inter="http://119.29.29.29/d?dn="
|
|
||||||
wget --quiet --output-document=- $inter$1
|
wget --quiet --output-document=- $inter$1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 读取接口数据
|
# Get data
|
||||||
# 参数: 接口类型 待提交数据
|
# arg: type data
|
||||||
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'}"
|
||||||
@@ -41,33 +79,37 @@ arApiPost() {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
# 更新记录信息
|
# Update
|
||||||
# 参数: 主域名 子域名
|
# arg: main domain sub domain
|
||||||
arDdnsUpdate() {
|
arDdnsUpdate() {
|
||||||
local domainID recordID recordRS recordCD
|
local domainID recordID recordRS recordCD myIP
|
||||||
# 获得域名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/')
|
||||||
# 获得记录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/')
|
||||||
# 更新记录IP
|
|
||||||
recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_line=默认")
|
# Update IP
|
||||||
recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/')
|
myIP=$(arIpAddress)
|
||||||
# 输出记录IP
|
recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_type=A&value=${myIP}&record_line=默认")
|
||||||
if [ "$recordCD" == "1" ]; then
|
recordCD=$(echo $recordRS | sed 's/.*{"code":"\([0-9]*\)".*/\1/')
|
||||||
echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/'
|
|
||||||
|
# Output IP
|
||||||
|
if [ "$recordCD" = "1" ]; then
|
||||||
|
echo $recordRS | sed 's/.*,"value":"\([0-9\.]*\)".*/\1/'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# 输出错误信息
|
# Echo error message
|
||||||
echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/'
|
echo $recordRS | sed 's/.*,"message":"\([^"]*\)".*/\1/'
|
||||||
}
|
}
|
||||||
|
|
||||||
# 动态检查更新
|
# DDNS Check
|
||||||
# 参数: 主域名 子域名
|
# 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}"
|
||||||
@@ -81,9 +123,9 @@ arDdnsCheck() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
###################################################
|
# DDNS
|
||||||
# 检查更新域名
|
echo ${#domains[@]}
|
||||||
|
for index in ${!domains[@]}; do
|
||||||
arDdnsCheck "anrip.com" "lab"
|
echo "${domains[index]} ${subdomains[index]}"
|
||||||
arDdnsCheck "anrip.net" "dev"
|
arDdnsCheck "${domains[index]}" "${subdomains[index]}"
|
||||||
|
done
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
arMail="test@gmail.com"
|
||||||
|
arPass="test"
|
||||||
|
|
||||||
|
declare -a domains=("test.net")
|
||||||
|
declare -a subdomains=("abc")
|
||||||
Reference in new issue
Block a user