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

這篇文章主要是針對RouterOS更新到ChangeIP上所寫的

(這是非官方的Scripts.要自行設定那個interface是update ip to DDNS)
把主要的Script改一下即可。

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

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

相關的Script如下

#以下程式碼於RouterOS 3.7下測試通過
 
:log info "DDNS: Begin"
:local ddnsuser "你的帳號"
:local ddnspass "你的密碼"
:local ddnshost "名稱(如為test.changeip.net的話,請填test)"
:local ddnszone "網域(如為test.changeip.net的話,請填changeip.net)"
:local ddnsinterface "你要更新上去IP所使用的介面名稱(pppoe-out)"
#一定要先宣告,不然後面程式無法使用
:global ddnslastip
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
#舊的IP有存在就用舊的,不存在就建0.0.0.0/0
:if ([:typeof [:global ddnslastip]] = nil ) do={ :global ddnslastip 0.0.0.0/0 } else={ :set ddnslastip $ddnslastip }
:if ([:typeof [:global ddnsip]] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
    :if ($ddnsip != $ddnslastip) do={
        :log info "DDNS: 開始更新DDNS!"
        :log info ([/tool dns-update key-name=$ddnsuser key=$ddnspass name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] zone=$ddnszone] . "更新IP:" . $ddnsip)
 
        :global ddnslastip $ddnsip
} else={
        :log info "DDNS: IP無變動"
}
}
:log info "DDNS: End"

新增後還要在 scheduler 中設定每3分鐘運行一次
GUI
RouterOS > Menu > System > Scheduler [Add Scheduler]
Name: ddns-update-cip-uo
Start Time: startup
Interval: 00:03:00
On Event: /system script run ddns-changeip-uo

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

關於 cyrus