One of my customers got an ADSL line with dynamic IP address.
A script for DynDNS update is scheduled every 15 min and works fine:
Code: Select all
# Set needed variables
:local username "user"
:local password "pass"
:local hostname "myhost.dyndns.info"
:global dyndnsForce
:global previousIP
# print some debug info
# :log info ("dyndns-update: username = $username")
# :log info ("dyndns-update: password = $password")
:log info ("dyndns-update: hostname = $hostname")
:log info ("dyndns-update: previousIP = $previousIP")
# 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"
: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 "dyndns-update: currentIP = $currentIP"
# 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 ("dyndns-update: Dyndns update needed")
:log info ("dyndns-update: Dyndns Update Result: ".$result)
} else={
:log info ("dyndns-update: No dyndns update needed")
}
Code: Select all
/tool netwatch
add disabled=no down-script="led user-led=no\r\
\n:log info \"Host 208.67.220.220 unreachable\"\r\
\n" host=208.67.222.222 interval=1m timeout=1s up-script="led user-led=yes\r\
\n/system script run dyndns-update\r\
\n:log info \"Host 208.67.220.220 reachable\"\r\
\n\r\"
global variable 'previousIP' seems to be empty instead of containing IP address string.
Below is a log:
Code: Select all
21:45:00 script,info dyndns-update: hostname = myhost.dyndns.info
21:45:00 script,info dyndns-update: previousIP = 183.26.221.45
21:45:01 info fetch: file "dyndns.checkip.html" created
21:45:01 script,info dyndns-update: currentIP = 183.26.221.45
21:45:01 script,info dyndns-update: No dyndns update needed
21:54:11 system,info netwatch host modified by admin
21:54:11 script,info dyndns-update: hostname = myhost.dyndns.info
21:54:11 script,info dyndns-update: previousIP =
21:54:11 info fetch: file "dyndns.checkip.html" created
21:54:12 script,info dyndns-update: currentIP = 183.26.221.45
21:54:13 info fetch: file "dyndns.txt" created
21:54:13 script,info dyndns-update: Dyndns update needed
21:54:13 script,info dyndns-update: Dyndns Update Result: nochg 183.26.221.45
21:54:13 script,info Host 208.67.220.220 reachable
Does anyone noticed similar problem with global variables?
Or am I doing something wrong?
TIA,