MikroTik RouterOS: DynDNS Update Script
While i was testing a new product called mikrotik routeros i missed a feature which is available on every low budget router: The automatic DynDNS IP updater. After searching through the MikroTik Wiki and Google, i just found addons for ChangeIP and EveryDNS but nothing for DynDNS. Some poeple in the forum seems to miss it, too. So i took the two scripts above changed them to work with dynDNS.
1) Add a new Script called DynDNS in /system scripts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # Define User Variables :global ddnsuser "DYNDNSUSER" :global ddnspass "DYNDNSPASS" :global ddnshost "DYNDNSHOST" # Define Global Variables :global ddnsip :global ddnslastip :if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" } :global ddnsinterface :global ddnssystem ("mt-" . [/system package get system version] ) # Define Local Variables :local int # Loop thru interfaces and look for ones containing # default gateways without routing-marks :foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={ :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={ :global ddnsinterface [/ip route get $int interface] } } # Grab the current IP address on that interface. :global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ] # Did we get an IP address to compare? :if ([ :typeof $ddnsip ] = nil ) do={ :log info ("DynDNS: No ip address present on " . $ddnsinterface . ", please check.") } else={ :if ($ddnsip != $ddnslastip) do={ :log info "DynDNS: Sending UPDATE!" :local str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" /tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DynDNS.".$ddnshost) :delay 1 :local str [/file find name="DynDNS.$ddnshost"]; /file remove $str :global ddnslastip $ddnsip } } |
2) Add the scheduler entry to run the script every minute
/system scheduler add name=DynDNS interval=00:01 on-event="/system script run DynDns1\r\n"
Categories: it
Hi
Thanks for the script! Works like a charm!
Thanks
Marcel
It doesn’t work with me. When I print the script in terminal, it has a flag: Flags: I – invalid
When I try to run the script in terminal, I get:
system script run 0
interrupted
input does not match any value of value-name
I change the values for username, password and hostname.
@vlado
scroll nearly down, there is another solution
mikrotikforum