代碼: 選擇全部
#Script在RouterOS 5.0rc11中測試過
#Date:2010/04/11
#Script Name:DynDNSUpdate
#Script Describe:更新IP到DynDNS上面去
#定義使用者相關的變數,請於下面自行輸入
:local ddnsuser "你的DynDNS帳號"
:local ddnspass "你的DynDNS密碼"
:local ddnshost "你的完整網址名(例如:abcd.ath.cx)"
:local ddnsinterface "要更新的介面名稱(例如:pppoe-out1)"
#定義IP變數
:global ddnsipADSL1
:global ddnslastipADSL1
:if ([ :typeof $ddnslastipADSL1 ] = nil ) do={ $ddnslastipADSL1 "0" }
#取得介面的IP位置
:set ddnsipADSL1 [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
#去掉IP的網段
:set ddnsipADSL1 [:pick $ddnsipADSL1 0 [:find $ddnsipADSL1 "/"]]
#判斷是否需要進行更新
:if ([ :typeof $ddnsipADSL1 ] = nil ) do={
:log info ("DynDNS: " . $ddnsinterface . "介面上沒有IP,請確認")
} else={
:if ($ddnsipADSL1 != $ddnslastipADSL1) do={
:log info ("DynDNS:" . $ddnsinterface . "更新IP" . $ddnsipADSL1)
:local str "/nic/update?hostname=$ddnshost&myip=$ddnsipADSL1&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
/tool fetch address=members.dyndns.org src-path=$str mode=http user=$ddnsuser password=$ddnspass dst-path=("/DynDNS.".$ddnshost)
:delay 1
:local str [/file find name="DynDNS.$ddnshost"];
/file remove $str
#更新後把IP設為最新的IP
:global ddnslastipADSL1 $ddnsipADSL1
}
}