土法制造 DDNS 完整版

节日快乐! 最近我又对之前的脚本完善了一下, 添加了对 CloudFlare DNS API 的呼叫, 这样 DDNS 才名副其实吧:

#!/bin/bash
function update_dns {
 logger 'Prepare to update DNS...'
 curl -i https://www.cloudflare.com/api_json.html \
 -d 'a=rec_edit' \
 -d 'id=DOMAIN_ID' \
 -d 'tkn=THIS_IS_MY_KEY_GO_GET_YOURS' \
 -d 'email=MY_EMAIL' \
 -d 'z=raynix.info' \
 -d "content=$1" \
 -d 'type=A' \
 -d 'name=XXX' \
 -d 'ttl=1' |logger
}
url='http://direct.raynix.info/ip.php'
last='/tmp/extip'
rcpt='MY_EMAIL'
extip=`curl $url`
echo $extip |diff $last -
if [ $? == 0 ]; then
 sleep 1
else
 if [[ $extip =~ [0-9]+.[0-9]+.[0-9]+.[0-9]+ ]]; then
 logger 'last IP: ' `cat $last`
 logger 'new IP: ' $extip
 echo $extip > $last
 echo "New IP: $extip" |[email protected] mutt -s "IP Changed" $rcpt
 update_dns $extip
 fi
fi

以上脚本已通过实践检验, 但你用的话需要把那些大写的部分替换成你自己的哦. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *