#!/bin/bash # 启用IPv4或IPv6解析 enableIPv4=1 enableIPv6=0 # 启用代理 proxy=false # proxy=true # IPv4和IPv6域名 IPv4Domain="test.yourdomain.com" IPv6Domain="test.yourdomain.com" # Cloudflare API令牌和域ID ZONE_ID="" API_TOKEN="" # 获取当前IP地址 get_current_ip() { if [ "$1" == "A" ]; then curl -s 4.ipw.cn elif [ "$1" == "AAAA" ]; then curl -s 6.ipw.cn fi } # 管理DNS记录 manage_dns_record() { local recordType=$1 local domain=$2 local enable=$3 if [ -z "$domain" ]; then return fi local response=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?name=$domain&type=$recordType" \ -H "Authorization: Bearer $API_TOKEN" \ -H "Content-Type: application/json") local recordCount=$(echo "$response" | jq '.result | length') if [ "$recordCount" -gt 0 ]; then local recordID=$(echo "$response" | jq -r '.result[0].id') if [ "$enable" -eq 1 ]; then local currentIP=$(get_current_ip "$recordType") local recordContent=$(echo "$response" | jq -r '.result[0].content') local recordProxied=$(echo "$response" | jq -r '.result[0].proxied') if [ "$recordContent" == "$currentIP" ] && [ "$proxy" == "$recordProxied" ]; then echo "$recordType record for '$domain' has not changed. Current IP: $currentIP" else echo "$recordType record for '$domain' has changed or proxy status does not match. Updating..." local jsonData=$(cat <