Skip to content

Instantly share code, notes, and snippets.

@PyroSA
Created January 24, 2016 11:52
Show Gist options
  • Save PyroSA/77d6948f7d61b435358b to your computer and use it in GitHub Desktop.
Save PyroSA/77d6948f7d61b435358b to your computer and use it in GitHub Desktop.
MikroTik NoIp DDNS update script
# No-IP automatic Dynamic DNS update
#--------------- Change Values in this section to match your setup ------------------
# No-IP User account info
:local noipuser "username@gmail.com"
:local noippass "password1"
# Set the hostname or label of network to be updated.
# Hostnames with spaces are unsupported. Replace the value in the quotations below with your host names.
# To specify multiple hosts, separate them with commas.
:local noiphost "host.zapto.org"
# Change to the name of interface that gets the dynamic IP address
:local inetinterface "PppInterface"
#------------------------------------------------------------------------------------
# No more changes need
: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://dynupdate.no-ip.com/nic/update\3Fmyip=$currentIP"
:local noiphostarray
:set noiphostarray [:toarray $noiphost]
:foreach host in=$noiphostarray do={
# Check 1 - resolved IP
:local resolvedIP [:resolve $host];
# Check 2 - Saved response from NO-IP
:local filename ("no-ip_ddns_update-" . $host . ".txt")
:local savedMatch -1
:local savedIP "No File";
if ( [:len [/file find name=$filename]] > 0 ) do={
:set savedIP [/file get $filename contents]
:set savedMatch [:find $savedIP $currentIP -1]
}
# If either check fails, update IP
:if (($currentIP = $resolvedIP) && ($savedMatch >= 0)) do={
:log info "No-IP: Host $host already on No-IP with IP $resolvedIP"
} else={
:log info "No-IP: Sending update for $host - $resolvedIP saved as $savedIP"
/tool fetch url=($url . "&hostname=$host") user=$noipuser password=$noippass mode=http dst-path=$filename
:log info "No-IP: Host $host updated on No-IP with IP $currentIP"
}
}
} else={
:log info "No-IP: $inetinterface is not currently running, so therefore will not update."
}
@PyroSA
Copy link
Author

PyroSA commented Jan 24, 2016

Updated version of this:
http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_No-IP_DNS

The new revisions of the OS handle global variables differently, so I'm now just loading the previous IP from the file instead.
As a added bonus I added a DNS resolve as a double-check. I might give a false-positive while the DNS updates, but better safe than sorry.

@fastzombies
Copy link

fastzombies commented Nov 23, 2016

Hello, what version of RouterOS is this for? Will it work with 6.37.x? Thanks.

@gkuhnen
Copy link

gkuhnen commented Feb 6, 2020

Working on 6.46.2.
Thanks.

@Josiasjjcc20
Copy link

Good morning. Today you have been able to use this script.? try to use it and don't update the ip the no-ip dashboard, note that I am behind a balancer.

@PyroSA
Copy link
Author

PyroSA commented May 1, 2020

The router and my no-ip account hasn't been used in almost a year, sorry.
Only ever used it on my (very simple) home network.

@RHACOR
Copy link

RHACOR commented Sep 9, 2022

Working on version 6.49.6
Thanks

GRACIAS

@aguerra-ar
Copy link

It works!
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment