Skip to content

Instantly share code, notes, and snippets.

@manueldev
Created August 17, 2023 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manueldev/cd1276b7e0f14773d8be0f3526a869a3 to your computer and use it in GitHub Desktop.
Save manueldev/cd1276b7e0f14773d8be0f3526a869a3 to your computer and use it in GitHub Desktop.
No-ip updater for Mikrotik
## noip no-ip updater mikrotik behind nat
## read write policy test
# Set needed variables
:local username "username@gmail.com"
:local password "password-no-ip"
:local hostname "domain.ddns.net"
:global dyndnsForce
:global previousIP
# print some debug info
#:log info ("UpdateNOIP: username = $username")
#:log info ("UpdateNOIP: password = $password")
#:log info ("UpdateNOIP: hostname = $hostname")
:log info ("UpdateNOIP: previousIP = $previousIP")
#:log info ("UpdateNOIP: force = $dyndnsForce")
#if you need set a mangle output mark routing
/ip firewall address-list add list=dyndns address=checkip.dyndns.org timeout=50s
:delay 3
# 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"
:delay 3
: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 "UpdateNOIP: downloadedIP = $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="dynupdate.no-ip.com" \
src-path="nic/update\3Fhostname=$hostname&myip=$currentIP" \
dst-path="/dyndns.txt"
:delay 2
:local result [/file get dyndns.txt contents]
:log info ("UpdateNOIP: Update Result: ".$result)
:put ("Update Result: ".$result)
} else={
:log info ("UpdateNOIP: No update needed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment