Tue Jun 01, 2010 12:21 am
The above script did most but not all of the work needed - the :global previousIP was not retained by 4.9 so I put in some additional code, using the same variables as the similar section to parse the result gathered from the web.
This script _does_ work for me using 4.9 - the remaining issue is that OpenDNS takes several minutes to update, during which time the script, if repeated at, say, 120s intervals, will try several times to update.
Anyone know how to put in a delay in a script - ideally the script will run every, say, 60s but then wait before completing after an update attempt for, say, 5 minutes to allow the updates to propagate...
# DNSoMatic Account Information
:global maticuser "<username>"
:global maticpass "password"
:global matichost "hostname"
# End of Account Information
:global previousIP
# Recover previous IP address from file
:local result [/file get $matichost contents]
:local resultLen [:len $result]
:local startLoc [:find $result "d " -1]
:set startLoc ($startLoc + 2)
:set previousIP [:pick $result $startLoc $resultLen]
# Print values for debug
:log info "DNSoMatic: Updating dynamic ip on DNS for $matichost"
# :log info "DNSoMatic: User: $maticuser ; Password: $maticpass"
:log info "DNSoMatic: Last ip address: $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 results
:local resultLen [:len $result]
:local startLoc [:find $result ": " -1]
:set startLoc ($startLoc + 2)
:local endLoc [:find $result "</body>" -1]
:global currentIP [:pick $result $startLoc $endLoc]
:log info "DNSoMatic: IP actual $currentIP"
# Touching the string passed to fetch command on "src-path" option
:local str "/nic/update?hostname=$matichost&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
:if ($currentIP != $previousIP) do={
:log info "DNSoMatic: Update needed"
:set previousIP $currentIP
:log info "DNSoMatic: Sending update to $currentIP"
:log info [ :put [/tool fetch host=MT user=$maticuser password=$maticpass mode=http address="updates.dnsomatic.com" src-path=$str dst-path=$matichost]]
:log info "DNSoMatic: Host $matichost updated on DNSoMatic with IP $currentIP"
} else={
:log info "DNSoMatic: Previous IP $previousIP and current IP $currentIP are equal: No update needed"
}
All I have done is to fix this - credit due to the original author, 't3wera', for getting it off the ground...
Ian