1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
mail="webmaster@example.com"
token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
domain="example.com"
target="ddns.example.com"
ip=$(curl -s -4 ip.sb)
zoneID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$domain" -H "X-Auth-Email: $mail" -H "X-Auth-Key: $token" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )
recordID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records?name=$target" -H "X-Auth-Email: $mail" -H "X-Auth-Key: $token" -H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*')
curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$recordID" \
-H "X-Auth-Email: $mail" \
-H "X-Auth-Key: $token" \
-H "Content-Type: application/json" \
--data '{"id":"$zoneID","type":"A","name":"$target","content":"$ip","proxied":false}'

chmod +x赋予运行权限,crontab -e定时任务走一波,Done.