MikroTik RouterOS script to toggle Wifi On & Off in case there is no internet connection

:if ([/ping 1.1.1.1 count=3] = 0) do={
    /interface wifi disable [find name="wifi-24GHz"];
    /interface wifi enable [find name="wifi-24GHz"];
}

Adding the script and the scheduler

Paste this into the terminal to automatically add the script and the scheduler, which runs it every minute:

/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:34