和 shell 脚本更新, 写到 cron 中,5 分钟检查一次
#!/bin/sh
TOKEN=tokentokentokentokentokentokentoken
ZONE_ID=zoneidzoneidzoneidzoneidzoneidzoneidzoneid
IDENTIFIER_AAAA=identifieridentifieridentifieridentifieridentifieridentifier
TYPE=AAAA
NAME_AAAA=xxx.abc.com
PROXIED=false
TTL=1
IP=`ping -6 ${NAME_AAAA} -c 1 |awk 'NR==2 {print $4}'`
echo "IP of ${NAME_AAAA} is ${IP}"
CONTENT=`ip address show ens192 | awk '/inet6/ && /2408/ {print substr($2,0,length($2)-3)}'`
echo "Local IP is ${CONTENT}"
if [ "${CONTENT}" = "${IP}" ]; then
echo "IP 相同,无需更新"
exit
fi
echo "start ddns refresh"
if [ x"${CONTENT}" != x ]; then
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$IDENTIFIER_AAAA" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" --data '{"type":"'$TYPE'","name":"'$NAME_AAAA'","content":"'$CONTENT'","proxied":'"$PROXIED"',"ttl":"'$TTL'"}'
echo ${CONTENT} > /tmp/ddnsResult
fi |