Thursday, June 6, 2013

Mikrotik v3.x compatible updater script

The blog is called Amiga Projects, but this post is an exception: it is about the Mikrotik scripting.

I have "googled" a lot to find a working and dyndns updater scripts which work on Mikrotik v 3.x. In Mikrotik forums there is a working NoIP updater script only for MT v 5.x. ChangeIP scripts are available for MT v 2.9, v 3.x and v 5.x (all tested).

So I have decided to adapt the ChangeIP script to work with NoIP dyndns records on Mikrotik v 3.x.

Here is the complete and updated (v 1.1) script. This version is more stable than v 1.0. It compares the IP address resolved by DNS server with the local IP address present on the dynamic interface. It sends update if the IP addresses are different.

# updater script
# v 1.1, 2013-08-29

# User variables
:local noipuser "username"
:local noippass "password"
:local noiphost "hostname"
:local noipinterface "interface"

# Get the current IP address
:local curip [ /ip address get [/ip address find interface=$noipinterface ] address ]

# Strip the net mask
:for i from=( [:len $curip] - 1) to=0 do={
  :if ( [:pick $curip $i] = "/") do={
    :set curip [:pick $curip 0 $i]

# Did we get an IP address to compare?
:if ([ :typeof $curip ] = nil ) do={
   :log info ("NoIP: No IP address present on " . $noipinterface)
} else={
  :local dnsip [:resolve $noiphost];
  :if ($curip != $dnsip) do={
    :log info ("NoIP: Sending update " . $dnsip)
    /tool fetch address="" src-path="nic/update\3Fhostname=$noiphost&myip=$curip" user=$noipuser password=$noippass keep-result=no
  } else={
    :log info "NoIP: No update required"

The current version updates only one NoIP host (NoIP supports 3 free hosts).

No comments:

Post a Comment