Dynamic DNS Update Script for DNSoMatic.com
From MikroTik Wiki
This script is a solution made of others solutions (nothing new). Much of this was adapted from Dynamic DNS Update Script for DNSoMatic.com behind NAT.
The goal is to update your account on DNSoMatic.com. The main advantage on this solution is that DNSoMatic offers the possibility of propagating DNS updates to thirth party DNSlike systems like OpenDNS, DynDNS, Change IP and other 27 more.
Note: The script below is RouterOS 5.11 Tested!
# DNSoMatic automatic DNS updates
# User account info of DNSoMatic
:global maticuser "username"
:global maticpass "password"
# Set the hostname to be updated. This is the part after the colon (:) on the DNSoMatic services page. Not sure if hostnames with spaces will work.
:global matichost "hostname"
# Change to the name of interface that gets the changing IP address
:global inetinterface "ether1"
# No more changes need
:global previousIP;
:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address];
# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
:local url "http://updates.dnsomatic.com/nic/update\3Fhostname=$matichost&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
:if ($currentIP != $previousIP) do={
:log info "DNSoMatic: Update needed"
:set previousIP $currentIP
:log info "DNSoMatic: Sending update $currentIP"
/tool fetch url=$url user=$maticuser password=$maticpass mode=http dst-path=dnsomaticupdate.txt
:log info "DNSoMatic: Host $matichost updated on DNSoMatic with IP $currentIP"
} else={
:log info "DNSoMatic: Previous IP $previousIP and current IP equal, no update need"
}
} else={
:log info "DNSoMatic: $inetinterface is not currently running, so therefore will not update."
}
This will also need you to configure scheduler entry for periodical runs.
hjoelr 20/dec/2011