# Your DynDNS account user-name, password & host-name.
:local username "yourusername"
:local password "yourpassword"
:local hostname "yourhostname"
# Which interface are we checking if DHCP has changed? [interfaces | name column in winbox]
:local DHCPInterface "yourinterface"
############
# This is the name of the file where the last recorded IP will be stored, as well as the file name of the DynDNS response.
# Make sure if another script is using files, that these names don't conflict.
# You probably also want to be sure they aren't the same as any other files on the disk - because you'll be clobbering those files.
# Finally, while I'm not aware of any "reserved" file names on the disk, it would be wise to avoid something that might conflict.
# Prefixing them with something to associate them with this script would probably be a good thing.
# You can point these files at your SD-disk too, if you have an SD card installed and ready on your RB. Just prefix the path appropriately:
# something like this [:local vLastIPFileName "micro-sd/dyndns-lastip.txt"] (don't put a leading slash)
# A user reported a bug if you use the RB flash and prefix the path with a [/]
# So for RB based flash, it's probably safest to use just something like [:local vLastIPFileName "dyndns-lastip.txt"] and not [:local vLastIPFileName "/dyndns-lastip.txt"]
# You ***MUST*** use a .txt extension. Just an oddity of ROS. Move along now.
# Code ForDD
:local vLastIPFileName "dyndns-lastip.txt"
:local vDynDNSResponseFile "dyndns-resp.txt"
# /dyndns.txt
############
# END Set needed variables
############
:local vlen;
:local vRawIP;
:local vJustIP;
:local currentIP
:local previousIP
:local vlocalurl
:local vIPChanged false
:local dyndnsresult
:local result
# Check for file existance, if not create it
# We need to do this before we try to read or write to files...
:local check [/file find name=$vLastIPFileName]
:if ( $check = "" ) do= {
/file print file=$vLastIPFileName
:delay 2
/file set [/file find name=$vLastIPFileName] contents=""
}
# Get the last saved IP from the file.
:set previousIP [/file get $vLastIPFileName contents]
#:put $previousIP
# print some debug info
:log info ("UpdateDynDNS: username = $username")
:log info ("UpdateDynDNS: password = $password")
:log info ("UpdateDynDNS: hostname = $hostname")
:log info ("UpdateDynDNS: previousIP = $previousIP")
:log info ("UpdateDynDNS: DHCPInterface = $DHCPInterface")
# This code gets the current IP from the interface.
# The interface we're checking should be set above.
# get the raw IP from the interface, which includes a mask.
:set vRawIP [:tostr [/ip address get [find interface=$DHCPInterface] address]]
#Strip the netmask off the vRawIP address.
:for i from=( [:len $vRawIP] - 1) to=0 do={
:if ( [:pick $vRawIP $i] = "/") do={
:set vJustIP [:pick $vRawIP 0 $i]
}
}
:set currentIP $vJustIP
# Determine if dyndns update is needed
# more dyndns updater request details http://www.dyndns.com/developers/specs/syntax.html
# Update if the currentIP isn't equal to previousIP.
:if (($currentIP != $previousIP)) do={
:log info "CurrentIP: $currentIP - PreviousIP: $previousIP"