From 3f6c9a494b89637099cb90411896f2bb4bd4ec16 Mon Sep 17 00:00:00 2001 From: Gaze Date: Mon, 7 Aug 2023 16:54:42 +0800 Subject: [PATCH] first commit --- ddns.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 ddns.sh diff --git a/ddns.sh b/ddns.sh new file mode 100755 index 0000000..9032c7e --- /dev/null +++ b/ddns.sh @@ -0,0 +1,20 @@ +#/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