MikroTik RouterOS 脚本:在没有互联网连接时切换 Wifi 开关
toggle_wifi.rsc
:if ([/ping 1.1.1.1 count=3] = 0) do={
/interface wifi disable [find name="wifi-24GHz"];
/interface wifi enable [find name="wifi-24GHz"];
}添加脚本和调度器
将此内容粘贴到终端中以自动添加脚本和调度器,调度器每分钟运行一次:
add_toggle_wifi_script.rsc
/system/script add dont-require-permissions=no name=toggle-wifi-if-no-internet owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
":if ([/ping 1.1.1.1 count=3] = 0) do={\
\n /interface wifi disable [find name=\"wifi-24GHz\"];\
\n /interface wifi enable [find name=\"wifi-24GHz\"];\
\n}"
/system scheduler add interval=1m name=toggle-wifi-if-no-internet on-event="/system script run toggle-wifi-if-no-internet" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=2025-04-24 start-time=13:21:34Check out similar posts by category:
MikroTik, Networking
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow