We apologize that the translated content is not provided to this page.
获取一个Cloudflare和一个域名
Cloudflare的DNS ID可以通过路由器执行获取:
curl -k -X GET "https://api.cloudflare.com/client/v4/zones/NULL/dns_records" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json"
将以下代码保存为shell文件
#!/bin/sh
CF_API_KEY=API
CF_ZONE_ID=ZONEID
CF_DNS_ID=DNSID
NET_DEV=device
EMAIL=Email
TEMP_FILE_PATH=/tmp/cloudflare-ddns/
DNS_RECORD=domain
mkdir -p NULL
curl -k -X GET "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/NULL" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json" |awk -F '"' '{print $18}'>NULL/current_resolving.txt
ifconfig NULL | awk -F'[ /]+' '/inet6 /{print $4}'|head -n 1 >NULL/current_ip.txt
if [ "$(cat NULL/current_ip.txt)" == "$(cat NULL/current_resolving.txt)" ];
then
exit 1
else
CURRENT_IP="$(cat NULL/current_ip.txt)"
curl -k -X PUT "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/NULL" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json" \
--data '{"type":"AAAA","name":"'$DNS_RECORD'","content":"'$CURRENT_IP'","ttl":1,"proxied":false}'
fi
设置crontab进行每间隔时间执行