Hi I’m new to Mikrotik and scripting. I’m writing a script to run on a Mikrotik Audience to update a Dynamic IP with my Domain. I know Mikrotik has a DYNDNS feature to their own cloud servers but the company hosting my Domain has it’s own API that can easily be accessed by formatting a URL. Is there anyway to have the script trigger on an IP Change event vs a recurring time interval? Seems like a waste of resources to have the jobs continually run.
With that said, is Mikrotik looking at implementing triggers on events for scripts rather than just scheduled time intervals?
Hi,
Sorry I don’t believe there is, well I couldn’t find any event driven anything in my research. Perhaps someone more enlightened can inform us both? But I agree with you event driven scripting and scheduling would be a welcome addition to RouterOS.
I know it’s not what you are after but it may help. Below is my script for Hurricane Electric (HE.net) Dynamic DNS. I just pop it in a schedule to run every 10 mins. You should be able to modify it to your needs by just pulling out the IP change detection components and running them at a fine interval.
:local currentIP
:local newIP
:local ddnshost "dynamic.domain"
:local key "key here"
:local updatehost "dyn.dns.he.net"
:local lookupserver "ns1.he.net"
:local WANinterface "ether1"
:local outputfile ("HE_DDNS" . ".txt")
:set newIP [/ip address get [/ip address find interface=$WANinterface] address]
:set newIP [:pick [:tostr $newIP] 0 [:find [:tostr $newIP] "/"]]
:set currentIP [:resolve $ddnshost server=$lookupserver]
#check error
:if ([:len $newIP] = 0) do={
:log error ("Could not get IP for interface " . $WANinterface)
:error ("Could not get IP for interface " . $WANinterface)
} else={
:if ($newIP != $currentIP) do={
:log info ("WAN IPv4 address $currentIP changed to $newIP")
:log info ("Updating DDNS IPv4 address" . " Client IPv4 address to new IP " . $newIP . "...")
/tool fetch mode=https url="https://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" dst-path=$outputfile
:set currentIP $newIP
:log info ([/file get ($outputfile) contents])
:log info ("Removing file")
# /file remove ($outputfile)
:log info ("File removed")
} else={
# :log info ("WAN IPv4 address has not changed")
}
}
I also use this little srciptlet to update my wanIP into an address list from the mikrotik address. you could run that often (once every 5 seconds or so) and then monitor for change? but I run this just on boot.
/ip firewall address-list add address=<your serial number>.sn.mynetname.net list=WAN-IP