Community discussions

 
hhspiny
just joined
Topic Author
Posts: 2
Joined: Mon Jan 12, 2015 10:19 pm

Google Dynamic DNS update script

Tue Jan 27, 2015 9:00 pm

This script was adapted from the script that updates entryDNS. tested on routerOS 6.x

# Variables
:local GoogleDNSUsername "xxx"
:local GOogleDNSPassword "xxx"
:local hostName "xxx"
:local GoogleDNSForceUpdate false
:local currentIP ""
:global previousIP

# Script

/tool fetch url="http://myip.dnsomatic.com/" mode=http dst-path="publicip.txt"
:set currentIP [/file get "publicip.txt" contents]
/file remove "publicip.txt"

:if ([:typeof $previousIP] = "nothing") do={ :set previousIP "" }

:if ($currentIP != $previousIP) do={
:set GoogleDNSForceUpdate true
:set previousIP $currentIP
}

:if ($GoogleDNSForceUpdate) do={
:do {
/tool fetch url="https://$GoogleDNSUsername:$GOogleDNSPa ... $currentIP" mode=https keep-result=no
:log info ("GoogleDNS Updated: current IP = $currentIP")
} on-error={
:log error ("GoogleDNS: Failed Updating")
}
}
 
craigthom
just joined
Posts: 8
Joined: Sat Mar 28, 2015 11:45 pm

Re: Google Dynamic DNS update script

Sun Mar 29, 2015 1:02 am

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") 
}
}
 
bjm904
just joined
Posts: 1
Joined: Tue Oct 25, 2016 12:09 am

Re: Google Dynamic DNS update script

Tue Oct 25, 2016 12:13 am

For those of you coming from google. The script posted by craigthom has a few typos. Below is the working script:
# 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 setResults [/file get GoogleDNS.txt contents];
:log info ("GoogleDNS said this: $setResults")
} on-error={ 
:log error ("GoogleDNS: script failed to set new IP address") 
}
}
 
jo2jo
Forum Veteran
Forum Veteran
Posts: 958
Joined: Fri May 26, 2006 1:25 am

Re: Google Dynamic DNS update script

Mon Oct 23, 2017 7:42 am

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") 
}
}

scheduler example, to auto run this every 5m
/system scheduler add interval=10m name=SCHgoogleDYNdns on-event=YOURdynSCRIPTname
:beep :beep :beep
 
tugsynz
just joined
Posts: 3
Joined: Thu Jul 18, 2019 11:09 pm

Re: Google Dynamic DNS update script

Thu Jul 18, 2019 11:12 pm

Hi Team,

I have used this script, I keep getting a reply stating its a "badagent"

Have I missed something in the script?

Thanks,
B

Who is online

Users browsing this forum: No registered users and 7 guests