# Set the variables TOKEN="ID,TOKEN" DOMAIN="example.com" SUB_DOMAIN="v6" RECORD_LINE="默认"
# Get the current public IPv6 address IPV6=$(curl -s https://v6.ident.me)
# Get the list of records RESULT=$(curl -s -L -X POST "https://dnsapi.cn/Record.List" \ -d "login_token=$TOKEN&format=json&domain=$DOMAIN")
# Find the record ID RECORD_ID=$(echo $RESULT | jq -r --arg SUB_DOMAIN "$SUB_DOMAIN" '.records[] | select(.name == $SUB_DOMAIN) | .id')
# Update the DNS record RESULT=$(curl -s -X POST "https://dnsapi.cn/Record.Modify" \ -d "login_token=$TOKEN&format=json&domain=$DOMAIN&sub_domain=$SUB_DOMAIN&record_id=$RECORD_ID&record_line=$RECORD_LINE&value=$IPV6&record_type=AAAA")
# Check the result if [[ $(echo $RESULT | jq -r '.status.code') == "1" ]]; then echo "DDNS update successful" echo $RESULT else echo "DDNS update failed" echo $RESULT fi
@echo off set TOKEN=ID,TOKEN set DOMAIN=example.com set SUB_DOMAIN=v6 set RECORD_LINE=默认
REM Get the current public IPv6 address for /f %%i in ('curl -s https://v6.ident.me') do set IPV6=%%i
REM Get the list of records for /f "tokens=*" %%a in ('curl -s -L -X POST "https://dnsapi.cn/Record.List" -d "login_token=%TOKEN%&format=json&domain=%DOMAIN%"') do ( set "RESULT=%%a" )
REM Find the record ID for /f "tokens=2 delims=:,}" %%b in ('echo %RESULT% ^| jq.exe -r --arg SUB_DOMAIN "%SUB_DOMAIN%" ".records[] | select(.name == $SUB_DOMAIN) | .id"') do ( set "RECORD_ID=%%b" )
REM Update the DNS record for /f "tokens=*" %%c in ('curl -s -X POST "https://dnsapi.cn/Record.Modify" -d "login_token=%TOKEN%&format=json&domain=%DOMAIN%&sub_domain=%SUB_DOMAIN%&record_id=%RECORD_ID%&record_line=%RECORD_LINE%&value=%IPV6%&record_type=AAAA"') do ( set "RESULT=%%c" )
REM Check the result for /f "tokens=2 delims=:,}" %%d in ('echo %RESULT% ^| jq.exe -r ".status.code"') do ( set "STATUS_CODE=%%d" )
# Set the variables $TOKEN = "ID,TOKEN" $DOMAIN = "example.com" $SUB_DOMAIN = "v6" $RECORD_LINE = "默认"
# Get the current public IPv6 address $IPV6 = (Invoke-WebRequest -Uri "https://v6.ident.me").Content.Trim()
# Get the list of records $RESULT = Invoke-WebRequest -Uri "https://dnsapi.cn/Record.List" -Method POST -Body @{ "login_token" = $TOKEN "format" = "json" "domain" = $DOMAIN } | ConvertFrom-Json
# Find the record ID $RECORD_ID = ($RESULT.records | Where-Object { $_.name -eq $SUB_DOMAIN }).id