MikroTik – DynDNS Update Script

This is a script for ensuring that your DynDNS hostname is updated when your IP changes on your MikroTik router. Unfortunately the script from the MikroTik Wiki doesn’t work and is broken.

http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_dynDNS

  • There is a question mark within the URL that posts the update to members.dyndns.org and it gets removed when you paste and run the code through telnet/ssh. To fix it you will need to put a slash in-front of the question mark for it to be passed correctly.

This script is now on GitHub at https://github.com/jordantrizz/mikrotik-scripts/blob/master/dyn-dns

# Set needed variables
:local username "username"
:local password "password"
:local hostname "hostname"

:global dyndnsForce
:global previousIP 

# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")

# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"
:local result [/file get dyndns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info "UpdateDynDNS: currentIP = $currentIP"

# Remove the # on next line to force an update every single time - useful for debugging,
# but you could end up getting blacklisted by DynDNS!

#:set dyndnsForce true

# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
   :set dyndnsForce false
   :set previousIP $currentIP
   :log info "$currentIP or $previousIP"
   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" \
      src-path="/nic/update\?hostname=$hostname&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" \
      dst-path="/dyndns.txt"
   :local result [/file get dyndns.txt contents]
   :log info ("UpdateDynDNS: Dyndns update needed")
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)
   :put ("Dyndns Update Result: ".$result)
} else={
   :log info ("UpdateDynDNS: No dyndns update needed")
}

Did you like this article?


0 Shares:
You May Also Like

Mobile Chat iPhone Application Updates and News About Latest Release

I was just forwarded a link to the blog of Mobile Chat's company Twenty08's. You can view it here - twenty08. There is some interesting information that was just posted today. Information that a lot of people have been looking for over the last little while after purchasing the Mobile Chat iPhone Application on Apples Application Store. The two recent posts go in depth into some of the problems with the Mobile Chat Application on the iPhone, a new version being released and how they're trying to fix the problems everyone is experiencing.
Read More

Linux computer that takes only 8 watts of power and can be solar powered

I know everyone is loving the new Asus Eee PC and they should, its a wonderful device. But if you want to go even smaller you can take a look at Aleutia E1 it only takes 8 watts of power and can be charged using solar power. Definitely for the out and out and about type traveler that needs a small computer that can be charged easily, combined with a sattlite phone for data and you have all that you need in a remote location.

Read More