-
-
Save 4ft35t/510897486bc6986d19cac45b3b9ca1d0 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
## edit this | |
cf_ddns_host=myddns.mydomain.com | |
# My Profile - API Tokens - Create Token - Use template of Edit zone DNS - Zone Resources - Include - All zones - Continue to summary - Create Token | |
cf_token= | |
## edit end | |
# auto fetch | |
cf_zoneid= | |
cf_recordid= | |
servers=' | |
http://myip.ipip.net/s | |
http://ipinfo.io/ip | |
http://ipecho.net/plain | |
http://members.3322.org/dyndns/getip | |
http://ip.sb | |
http://ifconfig.me | |
' | |
cfcurl(){ | |
curl -H "Authorization: Bearer $cf_token" -H "Content-Type: application/json" $@ | |
} | |
# get root domain | |
get_cf_ids(){ | |
domain=$(curl "http://223.5.5.5/resolve?name=$cf_ddns_host&type=ns" | tr , '\n' | awk -F'"' '/Authority/{print $(NF-1)}') | |
cf_zoneid=$(cfcurl "https://api.cloudflare.com/client/v4/zones?name=$domain" \ | |
| tr , '\n' \ | |
| awk -F'"' '/"id"/{print $(NF-1)}' \ | |
| head -1 | |
) | |
cf_recordid=$(cfcurl -X GET "https://api.cloudflare.com/client/v4/zones/$cf_zoneid/dns_records?type=A&name=$cf_ddns_host" \ | |
| tr , '\n' \ | |
| awk -F'"' '/"id"/{print $(NF-1)}' \ | |
| head -1 | |
) | |
sed -i "s/^cf_zoneid=.*$/cf_zoneid=$cf_zoneid/" $0 | |
sed -i "s/^cf_recordid=.*$/cf_recordid=$cf_recordid/" $0 | |
} | |
for s in $servers | |
do | |
ip=$(curl -s -m3 $s) | |
[ "$ip" ] && break | |
done | |
[ "$cf_recordid" ] || get_cf_ids | |
cfcurl -X PUT "https://api.cloudflare.com/client/v4/zones/$cf_zoneid/dns_records/$cf_recordid" \ | |
--data '{"type":"A","name":"'$cf_ddns_host'","content":"'$ip'","ttl":3600,"proxied":false}' |
How to run this correctly ? Im getting API UPDATE FAILED. DUMPING RESULTS:
{"success":false,"errors":[{"code":7001,"message":"Method PUT not available for that URI."}],"messages":[],"result":null}
command trying is ./cloudflare-update-record.sh and ./cloudflare-update-record.sh -ip=192.168.1.1
How to run this correctly ? Im getting API UPDATE FAILED. DUMPING RESULTS:
{"success":false,"errors":[{"code":7001,"message":"Method PUT not available for that URI."}],"messages":[],"result":null}command trying is ./cloudflare-update-record.sh and ./cloudflare-update-record.sh -ip=192.168.1.1
./cloudflare-update-record.sh
works for me. And this scripts run without any args.
To debug it, run with
bash -x cloudflare-update-record.sh
Please update. I update for https://ctviet.com but error alert: API UPDATE FAILED. DUMPING RESULTS
Please update. I update for https://ctviet.com but error alert: API UPDATE FAILED. DUMPING RESULTS
Works for me. Please paste the next line after API UPDATE FAILED. DUMPING RESULTS
rm cloudflare.ids, and replace 4-7 line to your own info.