From 346ea58472f2ac23a7d1ee5527cdb3e51c5f6b3f Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Wed, 12 Sep 2018 08:45:33 -0600 Subject: [PATCH] Get current IP and record ID at CloudFlare for specified DNS records --- cfddns.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cfddns.sh b/cfddns.sh index 17bfbfc..75ac5b6 100755 --- a/cfddns.sh +++ b/cfddns.sh @@ -109,6 +109,8 @@ errorExplain=() dnsRecords=() cfDetails=() cfRecords=() +currentIP=() +recordID=() ip4=1 ip6=0 @@ -242,6 +244,30 @@ else done fi + +## Get existing IP address and identifier in CloudFlare's DNS records +for recordIdx in "${!cfRecords[@]}"; do + currentIP+=($(echo "${cfRecords[recordIdx]}" | \ + grep -Po '(?<="content":")[^"]*')) + recordID+=($(echo "${cfRecords[recordIdx]}" | \ + grep -Po '(?<="id":")[^"]*')) + echo -e "\e[1;36mIndex $recordIdx: \e[0mFor record\e[1;33m" \ + "${dnsRecords[recordIdx]}\e[0m" \ + "with ID: \e[1;33m${recordID[recordIdx]}\e[0m" \ + "the current IP is \e[1;35m ${currentIP[recordIdx]}\e[0m" +done + +## Check whether new IP matches old IP and update if they do not match +for recordIdx in "${!currentIP[@]}"; do + if [ ${currentIP[recordIdx]} = $ipAddress ]; then + echo -e "\e[0;32m${dnsRecords[recordIdx]} is up-to-date." + else + echo -e "\e[0;31m${dnsRecords[recordIdx]} needs updating." + fi +done + + + quit # this code should never be executed