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

這篇文章主要是針對RouterOS更新到
ChangeIP上所寫的
(這是官方的Scripts.會自行查詢那個interface是主要NAT後,就會自動設成用這個interface update ip to DDNS)
把主要的Script改一下即可。

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

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

相關的Script如下

# HomingBeacon Main Dynamic DNS Update Script
# Written by Sam Norris, ChangeIP.com
# 20100728 Tested on RouterOS 4.9
# 20110511 Tested on RouterOS 5.2
 
# Set your specific ChangeIP.com preferences here.
:global ddnsuser "USERID"
:global ddnspass "PASSWORD"
:global ddnshost "HOSTNAME.changeip.net"
# Change ddnsport to 8245 to bypass proxy.
:local ddnsport 80
 
# Do not edit anything below this line.  You have been warned.
# Abusive updates to the system will cause firewall blocks.
 
# Please be considerate and
# do not let this script run more than once per 3-5 minutes.
 
:log info "DDNS: Starting."
 
# Initialize checkpoint
:global ddnscheckpoint
:if ([:typeof $ddnscheckpoint] = "time") do={
	:log info ("DDNS: Last check was " . ([/system clock get time] - $ddnscheckpoint))
} else={
	:log info "DDNS: Cannot determine checkpoint, set now."
	:global ddnscheckpoint ( [/system clock get time] - 1d )
}
 
# Get the current IP
:if ([/system clock get time] - $ddnscheckpoint > [:totime 180s] || [/system clock get time] - $ddnscheckpoint < [:totime 0s]) do={
   :log info "DDNS: Performing remote IP detection."
   /tool fetch address="ip.changeip.com" host="ip.changeip.com" src-path=("/?" . [/int eth get 0 mac-address ]) dst-path="ip.changeip.com.txt" mode=http port=$ddnsport
   :global ddnscheckpoint [/system clock get time]
} else={
   :log info "DDNS: Please be considerate and wait a few seconds longer."
   :break
}
 
# Parse the IP address received from fetch script.
	:global ddnslastip
	:local html [/file get "ip.changeip.com.txt" contents]
	:local ddnsip [:pick $html ([:find $html "<!--IPADDR="] + 11) [:find $html "-->"] ]
 
# Is it a valid IP and is it different than the last one?
	:if ([:typeof [:toip $ddnsip]] = "ip" AND $ddnsip != $ddnslastip ) do={
		:log info "DDNS: Sending UPDATE with $ddnsip"
		:log info [/tool dns-update name=$ddnshost address=$ddnsip key-name=$ddnsuser key=$ddnspass ]
		:global ddnslastip $ddnsip
	} else={
		:log info "DDNS: No update required."
	}
}

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

 

 

-changeip-o

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

關於 cyrus