#!/bin/bash
domain_name=$1
record_name=$2
webhookurl=https://oapi.dingtalk.com/robot/send?access_token=0ccbf717fb61bef56d0cc29d25b5d7e79da719997c5d0dca55f709bd54e5ef32
time=$(date)
#currentdnsip=$(dig +short $record_name.$domain_name A)
currentrecordip=$(python3 /shell/listdns.py $domain_name $record_name)
currentserverip=$(timeout 5 curl -s ifconfig.me)
message="{
\"msgtype\": \"markdown\",
\"markdown\": {
\"title\": \"DNS记录修改\",
\"text\": \"#### DNS记录修改\n\n- 时间: **$time**\n- 域名: **${record_name}.${domain_name}**\n- IP:**$currentserverip**\n\"
}
}"
if [ "$currentrecordip" = "$currentserverip" ]; then
echo "The current DNS IP and server IP are the same: $currentrecordip"
exit 0
else
echo "The current DNS IP ($currentrecordip) does not match the server IP ($currentserverip). Updating DNS..."
python3 /shell/changedns.py $domain_name $record_name $currentserverip
curl -s "${webhookurl}" -H 'Content-Type: application/json' -d "${message}"
fi |