{"id":64,"date":"2015-09-01T13:26:57","date_gmt":"2015-09-01T13:26:57","guid":{"rendered":"http:\/\/mlapshin.com\/?p=64"},"modified":"2015-09-01T20:31:13","modified_gmt":"2015-09-01T20:31:13","slug":"mikrotik-and-dads-job","status":"publish","type":"post","link":"https:\/\/mlapshin.com\/index.php\/2015\/09\/01\/mikrotik-and-dads-job\/","title":{"rendered":"MikroTik and dad&#8217;s job"},"content":{"rendered":"<p>Being a dad is not an easy job. After returning from a long vacation my daughter developed a bad habit of staying\u00a0pretty 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.<\/p>\n<div id=\"attachment_67\" style=\"width: 217px\" class=\"wp-caption alignright\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-67\" class=\"wp-image-67\" title=\"MikroTik RB951G-2HnD Wireless Router\" src=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/08\/mikrotik_router-300x300.jpg\" alt=\"MikroTik RB951G-2HnD Wireless Router\" width=\"207\" height=\"207\" srcset=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/08\/mikrotik_router-300x300.jpg 300w, https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/08\/mikrotik_router-150x150.jpg 150w, https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/08\/mikrotik_router.jpg 500w\" sizes=\"auto, (max-width: 207px) 100vw, 207px\" \/><p id=\"caption-attachment-67\" class=\"wp-caption-text\">MikroTik router<\/p><\/div>\n<p>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\u00a0<em>MikroTik RB951G-2HnD<\/em> Wireless Router. It has been\u00a0serving me <span class=\"b-translation__text\">faith<\/span>fully\u00a0for\u00a0several months, but I still discover something interesting in it from time to time.<\/p>\n<p>I found the router could easily help me achieve the goal using built-in script support and\u00a0scheduler.\u00a0An interesting thing about the router is that it uses own operating system called <a href=\"http:\/\/www.mikrotik-routeros.net\/routeros.aspx\">RouterOS<\/a>, so scripting is not so easy as it could be on a Linux system. But it is a chance to learn one more\u00a0programming language. The complete scripting language documentation could be found <a href=\"http:\/\/wiki.mikrotik.com\/wiki\/Manual:Scripting\">here<\/a>.<\/p>\n<p>After a bit of reading and playing around I found that I need just a couple of 1-line scripts as simple as<\/p>\n<pre>interface wireless disable wlan1\r\n<\/pre>\n<p>where <em><code>wlan1<\/code> <\/em>is the name of my router wireless interface and <em><code>disable<\/code> <\/em>could be switched to <em><code>enabled<\/code><\/em>.<\/p>\n<p><a href=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/09\/Mikrotik_settings_w_menu.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-80 size-thumbnail\" title=\"WinBox App screen shot with all the required settings\" src=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/09\/Mikrotik_settings_w_menu-150x150.png\" alt=\"Mikrotik_settings_w_menu\" width=\"150\" height=\"150\" \/><\/a>There are three ways how the scripts could be created and scheduled: good old console, web client and the WinBox\u00a0app. 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.<\/p>\n<p>All required settings could be found on the screen shot at the left (click to see it).<\/p>\n<p>All the detailed steps are below.<\/p>\n<h3>How to create scripts<\/h3>\n<ol>\n<li>Open <em>System -&gt; Scripts<\/em> window<\/li>\n<li>Press <em>Add<\/em> button and the script editor window will open\n<ol>\n<li>Type a script name like <em>DisableWLAN<\/em><\/li>\n<li>Select policies required by the script or check all of them<\/li>\n<li>Type script into the source text area:\u00a0<em>interface wireless disable wlan1<\/em>\n<ol>\n<li>Make sure you are using the proper name of the wireless interface. It could be found in the <em>Interfaces<\/em>\u00a0section.<\/li>\n<\/ol>\n<\/li>\n<li>Next you can try to test\u00a0the script with &#8220;Run Script&#8221; button<\/li>\n<li>Save the script with &#8220;OK&#8221; button<\/li>\n<\/ol>\n<\/li>\n<li>Create a similar <em>EnableWLAN<\/em> script.<\/li>\n<\/ol>\n<h3>How to schedule scripts<\/h3>\n<ol>\n<li>Open\u00a0<em>System -&gt; Scheduler<\/em> window<\/li>\n<li>Press <em>Add <\/em>button to open the <em>Scheduler<\/em> window\n<ol>\n<li>Type some meaningful name for the scheduled task like <em>DisableWLAN<\/em><\/li>\n<li>Type the name of your script into the <em>On Event\u00a0<\/em>text area like <em>DisableWLAN<\/em><\/li>\n<li>Select the start date, start time (hh:mm:ss format) and the interval for repeating the action like <em>1d 00:00:00 <\/em>(it means one day and no hours, minutes and secs)<\/li>\n<li>Select required policies or check them all<\/li>\n<li>Save the schedule with &#8220;OK&#8221; button<\/li>\n<\/ol>\n<\/li>\n<li>Repeat the same to schedule the enabling script<\/li>\n<\/ol>\n<p>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.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-86 size-medium\" src=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/09\/Bart-over-Homer-300x169.jpg\" alt=\"Sleepy Homer and Bart\" width=\"300\" height=\"169\" srcset=\"https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/09\/Bart-over-Homer-300x169.jpg 300w, https:\/\/mlapshin.com\/wp-content\/uploads\/2015\/09\/Bart-over-Homer.jpg 620w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being a dad is not an easy job. After returning from a long vacation my daughter developed a bad habit of staying\u00a0pretty late in social networks. One day I was seriously asked by my wife that I should do my&hellip; <br \/><a class=\"read-more-button\" href=\"https:\/\/mlapshin.com\/index.php\/2015\/09\/01\/mikrotik-and-dads-job\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":83,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[6,5],"class_list":["post-64","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-tos","category-programming","tag-how-to","tag-mikrotik"],"_links":{"self":[{"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/posts\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":27,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions\/110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/media\/83"}],"wp:attachment":[{"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mlapshin.com\/index.php\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}