Skip to content

Instantly share code, notes, and snippets.

@manueldev
Created March 17, 2020 14:22
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/8d8b3806a632d26a91612cbca8000d9c to your computer and use it in GitHub Desktop.
Save manueldev/8d8b3806a632d26a91612cbca8000d9c to your computer and use it in GitHub Desktop.
## noip no-ip updater mikrotik behind nat
## read write policy test
# Set needed variables
:local username "@gmail.com"
:local password ""
:local hostname ".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")
# 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 1
: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: 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="dynupdate.no-ip.com" \
src-path="nic/update\3Fhostname=$hostname&myip=$currentIP" \
dst-path="/dyndns.txt"
:delay 1
: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