Being a dad is not an easy job. After returning from a long vacation my daughter developed a bad habit of staying pretty late in social networks. One day I was seriously asked by my wife that I should do my dad job one way or another. One option was just admonish daughter about this. However, as a true developer, I found a way how to reduce the issue to programming, he-he.
Using social networks requires access to the internet, so I decided to program my router to switch-off wi-fi access for the night time. I am a happy owner of MikroTik RB951G-2HnD Wireless Router. It has been serving me faithfully for several months, but I still discover something interesting in it from time to time.
I found the router could easily help me achieve the goal using built-in script support and scheduler. An interesting thing about the router is that it uses own operating system called RouterOS, so scripting is not so easy as it could be on a Linux system. But it is a chance to learn one more programming language. The complete scripting language documentation could be found here.
After a bit of reading and playing around I found that I need just a couple of 1-line scripts as simple as
interface wireless disable wlan1
where wlan1
is the name of my router wireless interface and disable
could be switched to enabled
.
There are three ways how the scripts could be created and scheduled: good old console, web client and the WinBox app. I found that the most convenient way for me is WinBox. However it is also possible to do all the same things in the console. The web UI turned out to be not so usable for script creation and scheduling.
All required settings could be found on the screen shot at the left (click to see it).
All the detailed steps are below.
How to create scripts
- Open System -> Scripts window
- Press Add button and the script editor window will open
- Type a script name like DisableWLAN
- Select policies required by the script or check all of them
- Type script into the source text area: interface wireless disable wlan1
- Make sure you are using the proper name of the wireless interface. It could be found in the Interfaces section.
- Next you can try to test the script with “Run Script” button
- Save the script with “OK” button
- Create a similar EnableWLAN script.
How to schedule scripts
- Open System -> Scheduler window
- Press Add button to open the Scheduler window
- Type some meaningful name for the scheduled task like DisableWLAN
- Type the name of your script into the On Event text area like DisableWLAN
- Select the start date, start time (hh:mm:ss format) and the interval for repeating the action like 1d 00:00:00 (it means one day and no hours, minutes and secs)
- Select required policies or check them all
- Save the schedule with “OK” button
- Repeat the same to schedule the enabling script
When I programmed the router, my daughter in a desperate attempt to stay up late even without the internet, found that I did a mistake and scheduled the enabling script at 7 minutes after the midnight instead of 7am and a couple of days more enjoyed the wi-fi in nights. Probably she could be a good tester someday.
Thanks for writing this article. I wrote a script to auto-renew my IPv6 address as MT seems to dump it after the lease is up. It doesn’t happen every time but this article was helpful!