一、创建 WOL 脚本
RouterOS定时唤醒脚本,唤醒局域网内IP10.10.10.39
,MAC地址A8:B8:E0:04:D1:DB
,网卡在网桥bridge1
。
- Ping 可靠性:单次 ping可能因网络抖动失败,建议增加到 count=3。
- 初始延迟:发送 WOL 后立即检查 ping 可能太快,短暂延迟为30s。
:local targetIP "10.10.10.39"
:local macAddress "A8:B8:E0:04:D1:DB"
:local interface "bridge1"
# 检查设备是否已经在线
:if ([/ping address=$targetIP count=3] > 0) do={
:log info "Device is already online, no need to send WOL."
} else={
# 发送 WOL
/tool wol mac=$macAddress interface=$interface
:delay 30s
# 等待设备上线,最多20次,每次间隔30秒
:local counter 0
:local isOnline false
:while ($counter < 20) do={
:if ([/ping address=$targetIP count=3] > 0) do={
:log info "WOL: Device is online, stopping retries"
:set isOnline true
:break
} else={
:set counter ($counter + 1)
:delay 30s
}
}
# 如果设备依然不可达,再次尝试发送 WOL
:if ($isOnline = false) do={
:log warning "WOL: First attempt failed, retrying WOL"
/tool wol mac=$macAddress interface=$interface
}
}
二、设置调度任务
然后,你需要使用调度任务让这个脚本在每天6点运行。可以通过以下命令来创建调度任务:
/system scheduler add name="WOL_SA6400" start-time=06:00:00 interval=1d on-event="/system script run wol_SA6400_script"
name="WOL_SA6400"
:任务名称start-time=06:00:00
:每天6点开始执行interval=1d
:每天执行一次on-event="/system script run wol_SA6400_script"
:执行你创建的脚本
这样,每天6点,MikroTik 路由器会自动运行 wol_SA6400_script
脚本,发送 WOL 信号。