[教學][Scripts]Dynamic DNS Update Script for (NO-IP-UO)

這篇文章主要是針對RouterOS更新到No-ip上所寫的
(這是非官方的Scripts.要自行設定那個interface是update ip to DDNS)

把主要的Script改一下即可。

GUI Mode 進入
RouterOS > Menu > System > Scripts [Add Scripts]

CLI Mode 進入
[admin@MikroTik] > system script add name=ddns-noip-uo

相關的Script如下

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# EDIT YOUR DETAILS / CONFIGURATION HERE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
# Define DDNS Accounts for RB Interfaces, one per interface.
 
# The RB interface
:global ddnsinterface "ether1"
# The DDNS Provider (Choice of NOIP, DYNDNS or EVERYDNS)
:global ddnsprovider "NOIP"
# The Hostname to update.
:global ddnshost "NOIPHOST"
# Your Account Username
:global ddnsuser "NOIPUSER"
# Your Account Password
:global ddnspass "NOIPPASS"
 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# END OF USER DEFINED CONFIGURATION
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
# Define Global Variables
:global ddnssystem ("mt-" . [/system package get system version] )
 
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip;] = "nil" ) do={ :set ddnslastip "0" }
 
:global ddnsprovname
:global str
:global ddnsprovaddress
:if ($ddnsprovider="NOIP") do={
  :set ddnsprovname "NoIP"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip"
  :set ddnsprovaddress "dynupdate.no-ip.com"
}
if ($ddnsprovider="DYNDNS") do={
  :set ddnsprovname "DynDNS"
  :set str "/nic/update?hostname=$ddnshost&myip=$ddnsip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
  :set ddnsprovaddress "members.dyndns.org"
}
if ($ddnsprovider="EVERYDNS") do={
  :set ddnsprovname "EveryDNS"
  :set str "/index.php?ver=0.1&ip=$ddnsip&domain=$ddnshost"
  :set ddnsprovaddress "dyn.everydns.net"
}
 
# Grab the current IP address on that interface.
:global ddnsip2 [/ip address get [/ip address find interface=$ddnsinterface ] address];
:set ddnsip [:pick $ddnsip2 0 [:find $ddnsip2 "/"]];
 
# Did we get an IP address to compare?
:if ([ :typeof $ddnsip;] = "nil" ) do={
   :log info ("NoIP: No ip address present on " . $ddnsinterface . ", please check.")
} else={
  :if ($ddnsip != $ddnslastip) do={
        :log info "$ddnsprovname: Sending UPDATE!"
         /tool fetch address=$ddnsprovaddress src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DDNS-".$ddnsprovname.".".$ddnshost)
  }
  :delay 1
  :set str [/file find name="DDNS-$ddnsprovname.$ddnshost"];
  /file remove $str
  :set ddnslastip $ddnsip
}
 
#:log info "DDNS Update script executed successfully."

新增後還要在 scheduler 中設定每分鐘運行一次

GUI
RouterOS > Menu > System > Scheduler [Add Scheduler]
Name: ddns-update-noip-uo
Start Time: startup
Interval: 00:01:00
On Event: /system script run ddns-noip-uo

CLI
[admin@MikroTik] > system scheduler add name=ddns-update-noip-uo interval=00:01 on-event="/system script run ddns-noip-uo\r\n"

關於 cyrus