MikroTik and dad’s job

Homer and Bart

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.

MikroTik RB951G-2HnD Wireless Router

MikroTik router

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.

Mikrotik_settings_w_menuThere 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

  1. Open System -> Scripts window
  2. Press Add button and the script editor window will open
    1. Type a script name like DisableWLAN
    2. Select policies required by the script or check all of them
    3. Type script into the source text area: interface wireless disable wlan1
      1. Make sure you are using the proper name of the wireless interface. It could be found in the Interfaces section.
    4. Next you can try to test the script with “Run Script” button
    5. Save the script with “OK” button
  3. Create a similar EnableWLAN script.

How to schedule scripts

  1. Open System -> Scheduler window
  2. Press Add button to open the Scheduler window
    1. Type some meaningful name for the scheduled task like DisableWLAN
    2. Type the name of your script into the On Event text area like DisableWLAN
    3. 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)
    4. Select required policies or check them all
    5. Save the schedule with “OK” button
  3. 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.

Sleepy Homer and Bart

1 Comment

  1. dakotac

    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!

Leave a Comment