极路由、小米路由器动态更新域名ddns脚本

作者: ropon 分类: 经验分享 发布时间: 2018-06-12 22:33
1、极路由

#!/bin/sh
DP_Id='dnspod_id'
DP_Key='dnspod_key'
DP_API="login_token=$DP_Id,$DP_Key&format=json&domain_id=xxxxxx&record_id=xxxxxx"
CURL=$(which curl)
Info_API="https://dnsapi.cn/Record.Info -d $DP_API"
wanip=$($CURL -s myip.idiyrom.com?type=ip)
realip=$($CURL -skX POST $Info_API |awk -F '"value":' '{print $2}'|awk -F '"' '{print $2}')
DP_API1="login_token=$DP_Id,$DP_Key&format=json&domain_id=xxxxxx&record_id=xxxxxx&sub_domain=xxx&value=$wanip&record_type=A&record_line_id=0"
Modify_API="https://dnsapi.cn/Record.Modify -d $DP_API1"
[ "${realip}A" != "${wanip}A" ] && $CURL -skX POST $Modify_API && echo "$(date "+%F %H:%M:%S") Domain xxx.xxxx.com A Record Update To $wanip" >> /var/log/dnspod.log



2、小米路由

#!/bin/sh
DP_Id='dnspod_id'
DP_Key='dnspod_key'
CURL=$(which curl)
wanip=$($CURL -s myip.idiyrom.com?type=ip)
realip=$($CURL -sX POST https://dnsapi.cn/Record.Info -d \
"login_token=$DP_Id,$DP_Key&format=json&domain_id=xxxxxx&record_id=xxxxxx" |awk -F '"value":' '{print $2}'|awk -F '"' '{print $2}')
[ "${realip}A" != "${wanip}A" ] && $CURL -sX POST https://dnsapi.cn/Record.Modify -d "login_token=$DP_Id,$DP_Key&format=json&domain_id=xxxxxx&record_id=xxxxxx&sub_domain=xxx&value=$wanip&record_type=A&record_line_id=0" && echo "$(date "+%F %H:%M:%S") Domain xxx.xxxx.com A Record Update To $wanip" >> /data/dnspod.log



3、添加计划任务,明天凌晨1点半执行脚本更新

crontab -e

30 1 * * * /data/myddns.sh >/dev/null 2>&1



4、添加开启自启脚本

cat /etc/rc.local

/bin/sh /data/myddns.sh

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!