RouterOS Italia

Versione completa: [Mikrotik] Dynamic DNS Update Script for dynDNS behind NAT
Al momento stai visualizzando i contenuti in una versione ridotta. Visualizza la versione completa e formattata.
Grateful thanks goes to "webasdf" on the forums (http://forum.mikrotik.com/viewtopic.php?...05#p171805)[url=http://forum.mikrotik.com/viewtopic.php?p=171805#p171805][/url] for this. I just edited it so that we can use the same identical script at every single one of our hotspots that are behind a Dynamic IP. The great ability of the original script by webasdf is that it uses DynDNS's html access method which means it will work behind a NAT'ed connection.
Codice:
# Set needed variables

Codice:
:local username "YourUsername"

Codice:
:local password "YourPassword"

Codice:
:local hostname "nohostset"


Codice:
:global dyndnsForce

Codice:
:global previousIP


Codice:
# print some debug info

Codice:
:log info ("UpdateDynDNS: username = $username")

Codice:
:log info ("UpdateDynDNS: hostname = $hostname")

Codice:
:log info ("UpdateDynDNS: previousIP = $previousIP")


Codice:
# get the current IP address from the internet (in case of double-nat)

Codice:
/tool fetch mode=http address="checkip.dyndns.org" src-path="/" dst-path="/dyndns.checkip.html"

Codice:
:local result [/file get dyndns.checkip.html contents]


Codice:
# parse the current IP result

Codice:
:local resultLen [:len $result]

Codice:
:local startLoc [:find $result ": " -1]

Codice:
:set startLoc ($startLoc + 2)

Codice:
:local endLoc [:find $result "</body>" -1]

Codice:
:local currentIP [:pick $result $startLoc $endLoc]

Codice:
:log info "UpdateDynDNS: currentIP = $currentIP"


Codice:
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by DynDNS!

Codice:
#:set dyndnsForce true


Codice:
# Determine if dyndns update is needed

Codice:
# more dyndns updater request details available at http://www.dyndns.com/developers/specs/syntax.html

Codice:
:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={

Codice:
   :set dyndnsForce false

Codice:
   :set previousIP $currentIP

Codice:
   /tool fetch user=$username password=$password mode=http address="members.dyndns.org" src-path="/nic/update?hostname=$hostname&myip=$currentIP" dst-path="/dyndns.txt"

Codice:
   :local result [/file get dyndns.txt contents]

Codice:
   :log info ("UpdateDynDNS: Dyndns update needed")

Codice:
   :log info ("UpdateDynDNS: Dyndns Update Result: ".$result)

Codice:
   :put ("Dyndns Update Result: ".$result)

Codice:
} else={

Codice:
   :log info ("UpdateDynDNS: No dyndns update needed")

Codice:
}