dnspod linux下纯bash IP更新程序

如果你有域名的话,申请个dnspod,建立个子域名,然后就能把你的动态ip随时的更新到你自己的子域名,神马3322 每步 花生壳……用着都很不舒服,synology DSM5.0里的dnspod更新程序有毛病,没法用,下面这个是大神写的纯bash更新脚本。。

 

#!/bin/sh
 
arPass=arMail=""
 
arIpAdress() {
    local inter="http://members.3322.org/dyndns/getip"
    wget --quiet --no-check-certificate --output-document=- $inter
}
 
arNslookup() {
    local dnsvr="114.114.114.114"
    nslookup ${1} $dnsvr | tr -d '\n[:blank:]' | sed 's/.\+1 \([0-9\.]\+\)/\1/'
}
 
arApiPost() {
    local agent="AnripDdns/3.08(mail@anrip.com)"
    local inter="https://dnsapi.cn/${1:?'Info.Version'}"
    local param="login_email=${arMail}&login_password=${arPass}&format=json&${2}"
    wget --quiet --no-check-certificate --output-document=- --user-agent=$agent --post-data $param $inter
}
 
arDdnsUpdate() {
    local domainID recordID recordRS recordCD

    domainID=$(arApiPost "Domain.Info" "domain=${1}")
    domainID=$(echo $domainID | sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/')

    recordID=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${2}")
    recordID=$(echo $recordID | sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/')

    recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${2}&record_line=默认")
    recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/')

    if [ "$recordCD" == "1" ]; then
        echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/'
        return 1
    fi

    echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/'
}
 
arDdnsCheck() {
    local postRS
    local hostIP=$(arIpAdress)
    local lastIP=$(arNslookup "${2}.${1}")
    echo "hostIP: ${hostIP}"
    echo "lastIP: ${lastIP}"
    if [ "$lastIP" != "$hostIP" ]; then
        postRS=$(arDdnsUpdate $1 $2)
        echo "postRS: ${postRS}"
        if [ $? -ne 1 ]; then
            return 0
        fi
    fi
    return 1
}
 
###################################################
#login email
arMail="helloworld@xx.com"	
#login password
arPass="password"

#sub domain
arDdnsCheck "hello.com" "shit"

 

上一篇
下一篇