#!/bin/sh -e
zone=$1
token=$2
domain=$3
\[ -e /tmp/$domain \] && old=$(cat /tmp/$domain)
cloudflaredns(){
id=$(curl -s “https://api.cloudflare.com/client/v4/zones/$zone/dns_records” -H “Authorization: Bearer $token” | sed -e ‘s/“id”/\\n/g’ | grep -w AAAA | grep -w $domain | awk -F" ‘{print $2}’)
if \[ -z “$id” \]; then
echo “ID not found”
else
status=$(curl -s -X PUT “https://api.cloudflare.com/client/v4/zones/$zone/dns_records/$id” -H “Authorization: Bearer $token” -H “Content-Type:application/json” -d ‘{“type”:"’“AAAA”‘“,“name”:”’“$domain”‘“,“content”:”’“$new”‘",“ttl”:1,“proxied”:false}’ | sed ‘s/.*“success”:(\[a-z\]+).*/\\1/’)
if \[ “$status” = “true” \]; then
echo $new > /tmp/$domain
fi
echo “$(date) $new $status”
fi
}
new=$(curl -6 test.ipw.cn)
if \[ -z “$new” \]; then
echo “No new IP found”
elif \[ “$old” = “$new” \]; then
echo “$(date) $new IP address unchanged”
else
cloudflaredns $new
fi
8 个赞
感谢分享 但是这个怎么用啊 佬
1 个赞
不错
应该是家里软路由或者nas使用的
1 个赞
不明觉厉
666
看不懂但觉得很厉害
写入脚本,然后:
ddns.sh 主域名ID 令牌 子域名
高深莫测