Mikrotik dynamischer DNS Eintrag bei SPDNS

Dies ist die Adaption dieses Dyndns-Skriptes.

Als erstes muss man das Skript zum System hinzufügen. Dazu zu System -> Scripts gehen.

Dort jetzt ein neues Skript mit dem Plus-Symbol hinzufügen und einen Namen eintragen – z.B. „spdns“. Den Namen brauchen wir gleich beim Zeitplaner.

Unten, in das Feld „Source“ muss folgendes Skript eingefügt werden:

# Set needed variables
:local username „<Username bei SPDNS>“
:local password „<Passwort bei SPDNS>“
:local hostname „<gewählter Domainname>“
:global dyndnsForce
:global 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“)
# get the current IP address from the internet (in case of double-nat)
/tool fetch mode=http address=“www.muon.de“ src-path=“/ip.php“ dst-path=“/spdns.checkip.html“
:delay 1
:local result [/file get spdns.checkip.html contents]

# parse the current IP result
:local resultLen [:len $result]
:local startLoc [:find $result „<IP>“ -1]
:set startLoc ($startLoc + 4)
:local endLoc [:find $result „</IP>“ -1]
:local currentIP [:pick $result $startLoc $endLoc]
:log info „UpdateDynDNS: currentIP = $currentIP“

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

#:set dyndnsForce true

:if (($currentIP != $previousIP) || ($dyndnsForce = true)) do={
:set dyndnsForce false
:set previousIP $currentIP
:log info „$currentIP or $previousIP“
/tool fetch user=$username password=$password mode=http address=“spdns.de“ \ src-path=“nic/update?hostname=$hostname&myip=$currentIP“ \
dst-path=“/spdns-log.txt“
#http://spdns.de/nic/update?hostname=$domain&myip=$IP&user=$username&pass=$password“
:delay 1
:local result [/file get spdns-log.txt contents]
:log info („UpdateDynDNS: Dyndns update needed“)
:log info („UpdateDynDNS: Dyndns Update Result: „.$result)
:put („Dyndns Update Result: „.$result)
} else={
:log info („UpdateDynDNS: No dyndns update needed“)
}

Mittels „Apply“ das Skript speichern und danach einmal testweise mit Run Script ausführen.

Unter „Log“ kann jetzt das Ergebnis angeschaut werden.

Wenn alles funktioniert, kann das Skript per Zeitplaner ausgeführt werden. Dazu nach System -> Scheduler gehen und mit Plus einen neuen Zeitplan erstellen. Der Name kann wieder beliebig gewählt werden, z.B.  “DDNS updater”.

Jetzt auf Start Time klicken und auf startup setzen. Bei Interval den Wert auf 00:10:00, also alle 10 Minuten, setzen.

Unten in der On Event box den Namen des Skriptes, also „spdns“, eintragen. Kein weiterer Zusatz.

Mittels OK oder Apply den Zeitplan einstellen. Unter „Run Count“ kann jetzt die Anzahl der Ausführungen und der nächste Ausführungszeitpunkt ermittelt werden.

 

Das war’s schon!