Jump to content



Microtik dynDNS Update Script.


GeorgeVasil

Recommended Posts

Επιτέλους κατι που παιζει σωστά με DynDNS.(Βιδο-κοντραα:p εχω φαει ολο το net).

http://forum.mikrotik.com/viewtopic.php?f=9&t=34575 @webasdf

I've made something similar and have been testing for a few weeks...just saw this post and thought I'd share. I haven't been locked out of dyndns yet, so this should be a good script as well. The main difference is that it queries checkip.dyndns.org for the current publicly facing IP address. I also set up a force update once every day at midnight. This prevents the dyndns domain from expiring due to it not being updated enough (which has happened to me in the past). The script has lots of logs and a few puts in it, but these can be safely deleted if desired. The policies on the scripts mentioned above still apply. Make sure those are set properly as well.

The Script "dyndns-update". Set the local variables username, password and hostname:

# Set needed variables
:local username "dyndnsUsername"
:local password "dyndnsPassword"
:local hostname "hostname.dyndns.org"

: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)
:put ("Dyndns Update Result: ".$result)
} else={
:log info ("dyndns-update: No dyndns update needed")
}

Script "dyndns-force". Intended to update dyndns only once every 24 hrs. If you run this too much, you may get locked out of dyndns.

:global dyndnsForce true
/system script run dyndns-update

Setup the schedulers. Run dyndns-update every 15 minutes and dyndns-force once every 24 hours:

/system scheduler add comment="" disabled=no interval=15m name=dyndns-update on-event=\
dyndns-update start-date=jan/01/1970 start-time=00:00:00
/system scheduler add comment="" disabled=no interval=1d name=dyndns-force on-event=\
dyndns-force start-date=jan/01/1970 start-time=02:00:00

ΟΥΑ!

(Διωρθωστε και εκεινο στο wiki του ΤWMN γιατι δεν παιζει με 3.30.)

Cheers,

GV

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Δημιουργία...

Important Information

Ο ιστότοπος theLab.gr χρησιμοποιεί cookies για να διασφαλίσει την καλύτερη εμπειρία σας κατά την περιήγηση. Μπορείτε να προσαρμόσετε τις ρυθμίσεις των cookies σας , διαφορετικά θα υποθέσουμε ότι είστε εντάξει για να συνεχίσετε.