Here is my modification, which uses /ip cloud to get the current address, eliminates the global variable for for the previous address by using :resolve, and captures and logs the results from Google.
# Variables
# Username and password are the long cryptic ones Google Domains provides,
# not your regular Google account ones
:local GoogleDNSUsername "yourDNSusername"
:local GoogleDNSPassword "yourDNSpassowrd"
:local hostName "yourhostname"
:local currentIP ""
:local setResults ""
:local previousIP ""
# Script
:set currentIP [/ip cloud get public-address]
:set previousIP [:resolve "$hostName"]
:if ($currentIP != $previousIP) do={
:do {
/tool fetch url="https://$GoogleDNSUsername:$GoogleDNSPassword@domains.google.com/nic/update?hostname=$hostName&myip=$currentIP" mode=https dst-path=GoogleDNS.txt
:set setresult [/file get GoogleDNS.txt contents];
:log info "GoogleDNS said this: $setResults"
} on-error={
:log error ("GoogleDNS: script failed to set new IP address")
}
}
This is an EXCELLENT script, thanks to OP for the main script (+others who have made changes and posted here)!!
my version/changes are tested working on rOS 6.40.4 and with Google Domains (Synthetic Records → Dynamic DNS).
below are some changes that I made that will maybe help others (it does what i specifically need it to do, that is grab current public IP from a DHCP-CLIENT interface, strip off the 3-char subnet, and securely reports that to your google domains dynDNS). In the snipit below, im “finding” the dhcp-client via a Comment i added to that dhcpClient (i use a preset comment, incase i ever change the ether3 interface’s name, at a later date, this script will still keep-on working )
note: alot of the addresses that you GET from ROS have the subnet appened to them, ie the /ip dhcp-client get command returns: 5.3.2.6/21 (so the code below STRIPPS OFF that /21 , or whatever subnet , IF it exists in your case)
My changes to OP script start at:
get the current…
and end at: #:log info ("currentIP…
DONT FORGET TO ALSO ADD THIS SCRIPT TO /SYS SCHEDULER SO THAT IT AUTO RUNS ON AN INTERVAL, example provided at bottom
# credit to hhspiny
#
# Variables
# Username and password are long cryptic ones Google Domains generates for your dynDomain,
# IT IS NOT your regular Google account Username and Password
#
:local GoogleDNSUsername "xxFILL_IN_YOURSxx"
:local GoogleDNSPassword "xxFILL_IN_YOURSxx"
:local hostName "xxxFILL_IN_YOURS_full__ex__DYN.MYDOMAIN.COMxxx"
:local currentIP ""
:local setResults ""
:local previousIP ""
# get the current IP address from a dhcp-client identified by a preset COMMENT FILL THIS IN BELOW
:set currentIP [/ip dhcp-client get [find comment=XXXyourCommentXXX] address]
# Strip netmask
:for i from=( [:len $currentIP] - 1) to=0 step=-1 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}
# comment OUT line below for DEBUGGING your GET IP ADDRESS command
#:log info ("currentIP_to_SEND_to_google_DEBUGGING: $currentIP")
:set previousIP [:resolve "$hostName"]
:if ($currentIP != $previousIP) do={
:do {
/tool fetch url="https://$GoogleDNSUsername:$GoogleDNSPassword@domains.google.com/nic/update?hostname=$hostName&myip=$currentIP" mode=https dst-path=GoogleDNS.txt
:set setResults [/file get GoogleDNS.txt contents];
:log info ("GoogleDNS said this: $setResults")
} on-error={
:log error ("GoogleDNS: script failed to set new IP address")
}
}