腳本在RB750,4.16版ros正常運行。
1、Winbox中,Tools->Email中做如下設置
Server:填入你的smtp服務商的地址。例如119.147.74.45,爲QQ的smtp服務器地址
Port:默認 25
From:你用來發信的電子郵件地址
User:smtp的帳號。 QQ的爲 xxxx(你的QQ號) @qq.com
Password:密碼
2、Winbox中,System->Scheduler,添加一個新任務
本例使用的www.changeip.com的動態域名服務
在腳本編輯框中輸入如下腳本:
:global ddnsuser "動態域名服務的帳戶名"
:global ddnspass "密碼"
:global ddnshost "動態域名 www.myxxx.ddns.com"
:global ddnsinterface "ADSL接口的名稱"
:global ddnssystem ("mt-" . [/system package get [/system package find name=system] version] )
:global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface] address ]
:global ddnslastip
:global Mailsendto "接受IP地址的email郵箱名"
# isUpdate和IssendMail爲兩個控制變量,isUpdate爲True時更新域名,isSendMail爲true時發送email到指定郵箱
:global isUpdate true
:global isSendMail true
:if ([:len [/interface find name=$ddnsinterface]] = 0 ) do={ :log info "DDNS: No interface named $ddnsinterface, please check configuration." }
:if ([ :typeof $ddnslastip ] = "nothing" ) do={ :global ddnslastip 0.0.0.0/0 }
:if ([ :typeof $ddnsip ] = "nothing" ) do={
:log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
} else={
:if ($ddnsip != $ddnslastip) do={
:if ( $isUpdate ) do={
:log info "DDNS: Sending UPDATE!"
/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"]] key-name=$ddnsuser key=$ddnspass
:log info "DDNS: UPDATE finished!"
}
:if ( $isSendMail ) do={
:global strDate [/system clock get date]
:global strTime [/system clock get time]
:global strSystemName [/system identity get name]
:log info "DDNS: Mail update is sending!"
/tool e-mail send to=$Mailsendto subject="DSL IP $strDate $strTime $strSystemName" body="DSL IP $ddnsip"
:log info "DDNS: Mail update finished!"
}
:global ddnslastip $ddnsip
} else={
:log info "DDNS: No changes necessary."
}
}
腳本運行間隔10~15分鐘.