GODADDY DDNS 自动更新脚本
把下面脚本放到,路径自己决定
/data/services/godaddy/ddns.sh
然后 crontab -e 添加,频率自己修改
*/5 * * * * /data/services/godaddy/ddns.sh >> /data/services/godaddy/ddns.log
顺便找了几个获取公网IP的接口
http://ip-api.com/json/?lang=zh-CN
有频率限制,不能短时间内重复调用,应该是因为可以查任意IP归属地,所以限制了
http://ip.taobao.com/service/getIpInfo.php?ip=myip
这个也可以任意查任意IP归属地
http://ip-api.com/json/113.97.18.125?lang=zh-CN
http://www.taobao.com/help/getip.php
ddns.sh
# 你的域名,注意不包括主机名
domain="king.com"
# 主机名,支持泛域名哦也支持 @
name="*"
# 登录 godaddy 查看
key="xxxxxxxxxxxxxxxx"
# 登录 godaddy 查看
secret="xxxxxxxxxxx"
headers="Authorization: sso-key $key:$secret"
cur_dateTime="`date +%Y-%m-%d,%H:%M:%S`";
echo $cur_dateTime;
# echo $headers
result=$(curl -s -X GET -H "$headers" \
"https://api.godaddy.com/v1/domains/$domain/records/A/$name")
dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "dnsIp:" $dnsIp
# 获取你的公网IP
ret=$(curl -s GET "http://pv.sohu.com/cityjson")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
echo "currentIp:" $currentIp
if [ "$dnsIp" != "$currentIp" ];
then
echo "Ips are not equal"
request='[{"data":"'$currentIp'","ttl":3600}]'
echo $request
nresult=$(curl -i -s -X PUT \
-H "$headers" \
-H "Content-Type: application/json" \
-d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
echo $nresult
fi