#/bin/bash EMAIL=$1 AUTH_KEY=$2 DOMAIN=$4 ZONE_ID=$3 CURRENT_IPV4=`curl -s http://ip.3322.net` DOMAIN_IPV4=`dig +short "$DOMAIN"` if [ "$DOMAIN_IPV4" == "$CURRENT_IPV4" ]; then echo "无需更新" exit 0 fi DOMAIN_ID=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=A&name=$DOMAIN&content=127.0.0.1&page=1&per_page=100&order=type&direction=desc&match=any" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTH_KEY" -H "Content-Type: application/json" | jq -r '.result[0].id'` result=`curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$DOMAIN_ID" -H "X-Auth-Email: $EMAIL" -H "X-Auth-Key: $AUTH_KEY" -H "Content-Type: application/json" --data '{"type":"A","name":"'"$DOMAIN"'","content":"'"$CURRENT_IPV4"'","ttl":120,"proxied":false}' | jq -r '.success'` if [ "$result" == "true" ]; then echo "更新成功!" exit 0 else echo "更新失败!" exit -1 fi