Created
December 1, 2012 00:54
-
-
Save hron84/4179837 to your computer and use it in GitHub Desktop.
DynDNS update script for MikroTik
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
# Set needed variables | |
:local username "YourUser" | |
:local password "YourPass" | |
:local hostname "yourhostname.dyndns.org" | |
:global dyndnsForce | |
:global previousIP | |
# print some debug info | |
:log info ("UpdateDynDNS: username = $username") | |
: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="ip.ezit.hu" src-path="/ip.php" dst-path="/dyndns.checkip.html" | |
:local result [/file get dyndns.checkip.html contents] | |
# parse the current IP result | |
:local resultLen [:len $result] | |
:local startLoc 0 | |
:local endLoc [:find $result " | |
" -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 available at http://www.dyndns.com/developers/specs/syntax.html | |
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={ | |
:set dyndnsForce false | |
:set previousIP $currentIP | |
/tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" 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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment