Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all articles
Browse latest Browse all 408

DYNU Script for Mikrotik (free dynamic dns script)

$
0
0

logo

An alternate to changeip.com (free ddns) with more features.

From few days , we were having issues in updating our mikrotik/linux base machines dynamic ip to free ddns service like changeip.com, therefore today I tested DYNU as an alternate and it worked very good. we can use it as backup or primary ddns service for our mikrotik routers.

First create account at http://www.dynu.com, add your required host. and then add script and schedule it to run after every 5  (or xx) minutes

Mikrotik Script for dynu ddns.

The below script is working 100% on Mikrotik 5.x and 6.x versions.
[Tested as of now / 1st-DEC-2015]

(You can copy paste following code in mikrotik by going to SYSTEMS / SCRIPTS / CLICK ON + sign to add script, and paste following.

NOTE: MAKE SURE YOU CHANGE THE REQUIRED FIELDS BEFORE DEPLOYMENT.

SCRIPT NAME: “DYNU”


###################
# CHANGE THE FOLLOWING ACCORDING TO YOUR CREDENTIALS
# Syed Jahanzaib / aacable at hotmail dot com
# Script taken from dynu.com for dynu
#########################
:global ddnsuser DYNU_USER
:global ddnspass "DYNU_PASSWORD"
:global theinterface "INTERFACE_NAME"
:global ddnshost "YOUR_DYNU_HOSTNAME.dynu.com"

#########################
# DONOT CHANGE BELOW THIS
#########################


:global ipddns [:resolve $ddnshost];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("DynuDDNS: No IP address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
:if ($ipddns != $ipfresh) do={
:log info ("DynuDDNS: IP-Dynu = $ipddns")
:log info ("DynuDDNS: IP-Fresh = $ipfresh")
:log info "DynuDDNS: Update IP needed, Sending UPDATE...!"
:global str "/nic/update?hostname=$ddnshost&myip=$ipfresh"
/tool fetch address=api.dynu.com src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/Dynu.".$ddnshost)
:delay 1
:global str [/file find name="Dynu.$ddnshost"];
/file remove $str
:global ipddns $ipfresh
:log info "DynuDDNS: IP updated to $ipfresh!"
} else={
:log info "DynuDDNS: dont need changes";
} }

Now run it and watch the results.


1-dynu 2- ddn2

3


 

To  scheudle it to run every 5 minutes , use


/system scheduler
add disabled=no interval=5m name=dynu on-event=dynu policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=jan/01/1970 \
start-time=00:00:00


 

Regard’s

Syed Jahanzaib

 


Filed under: Uncategorized

Viewing all articles
Browse latest Browse all 408

Trending Articles