Created
March 17, 2020 14:22
-
-
Save manueldev/8d8b3806a632d26a91612cbca8000d9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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