Anti Hack Protected BootLoader – MikroTik Script RouterOS

The way this script works is simple but smart, this script will monitor anyone who intends to activate the Mirotik Protected Bootloader, it will be detected immediately and the router will automatically shutdown immediately, when the router is turned on again, all the Protected Bootloader settings will be returned to the default setting, so any prank actions of malicious intruders before will be in vain

If after installing this script the router shuts down itself, don’t panic yet, it could be that the script is working and it might mean that someone is trying to activate the bootloader on the router illegally, if it’s true, this can be seen by changing the window caption or identity in Winbox to BOOTLOADER> Min: 00:00:20 – Max: 00:10:00

Why does this script have to change the identity or caption in Winbox? I am trying to think if the reset button and NetInstall don’t work at least we know how much time for the “reformat hold button” it takes and how long it takes to press the reset button for it to work. Please modify it, if you want it to be good, we can also add other information such as sending it to email or to telegram ?

For additional information, actually this script can not only be run through a schedule, because there are still many gaps that we can use to install the script.

Several locations can be installed to run the script:

– DHCP Client

– DHCP Server

– Hotspot Profile

– PPP Profile

– Netwatch tool

 

#=====================================================

# ANTI HACKER PROTECTED BOOTLOADER BY BUANANET SECURE!

#=====================================================

# Set Local String

:local logprotectedrouterboot;

:local logreformatholdbutton;

:local logreformatholdbuttonmax;

# Set local Input

:set logprotectedrouterboot “$[/system routerboard setting get protected-routerboot]”

:set logreformatholdbutton “$[/system routerboard setting get reformat-hold-button]”

:set logreformatholdbuttonmax “$[/system routerboard setting get reformat-hold-button-max]”

# Ckeck if Bootloader change to Enable

:if ($logprotectedrouterboot =”enabled”) do={

# Set info reformat hold button on Identity

/system identity set name=”BOOTLOADER > Min:$logreformatholdbutton – Max:$logreformatholdbuttonmax”

# Set back BootLoader to default config

/system routerboard setting set protected-routerboot disabled

/system routerboard setting set reformat-hold-button=20s

/system routerboard setting set reformat-hold-button-max=10m

# delay 5 second

:delay 5s

# Shutdown mikrotik or use /system reboot

/system shutdown

}

 

Auto Fix SNTP and Clock for Indonesia Timezone – MikroTik Script RouterOS

Time is very important for computers to do the right thing. If your clock is wrong by a minute authenticator apps won’t work. Wrong by an hour and Windows Networking has problems. Wrong by days and you risk SSL certificates expiring earlier (or later) than they should. VPNs may stop working. Datestamps on logs will be misleading. Generally, wrong time is a Bad Thing, and what is worse is the time the hotspot is out of sync with the Hotpspot Billing. Because Correct time is very important.

Manual Setup:

 

#==============================================

# Auto Repair TimeZone and clock By BuanaNET

#==============================================

# Waktu Indonesia Barat (WIB)  = +07:00

# Waktu Indonesia Tengah (WITA) = +08:00

# Waktu Indonesia Timur (WIT)  = +09:00 

#==============================================

# Ganti “+07:00” sesuaikan dengan daerah masing-masing

#==============================================

/system clock manual set time-zone=”+07:00″;

/system clock set time-zone-autodetec=no;

/system clock set time-zone-name=”manual”;

/ip cloud set update-time=no;

:local ntpServer “asia.pool.ntp.org”;

:local primary [resolve $ntpServer];

:local secondary [resolve $ntpServer];

/system ntp client set primary-ntp $primary;

/system ntp client set secondary-ntp $secondary;

/system ntp client set enabled=yes;

 

Complete Script With Scheduler

 

/system scheduler

add interval=1d name=SETTING-TIMEZONE on-event=”#=============================\

=================\r\

# Auto Repair TimeZone and clock By BuanaNET\r\

#==============================================\r\

# Waktu Indonesia Barat (WIB)  = +07:00\r\

# Waktu Indonesia Tengah (WITA) = +08:00\r\

# Waktu Indonesia Timur (WIT)  = +09:00 \r\

#==============================================\r\

# Ganti \”+07:00\” sesuaikan dengan daerah masing-masing\r\

#==============================================\r\

/system clock manual set time-zone=\”+07:00\”;\r\

/system clock set time-zone-autodetec=no;\r\

/system clock set time-zone-name=\”manual\”;\r\

/ip cloud set update-time=no;\r\

:local ntpServer \”asia.pool.ntp.org\”;\r\

:local primary [resolve \$ntpServer];\r\

:local secondary [resolve \$ntpServer];\r\

/system ntp client set primary-ntp \$primary;\r\

/system ntp client set secondary-ntp \$secondary;\r\

/system ntp client set enabled=yes;” policy=\

ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup

 

Auto Simple Queue From DHCP Server – MikroTik Script RouterOS

How To Creating Automatically Simple Queue using DHCP Server Lease Script

 

:local queueName “Client- $leaseActMAC”;

:if ($leaseBound = “1”) do={

 /queue simple add name=$queueName target=($leaseActIP . “/32”) max-limit=1M/2M comment=[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name];

} else={

    /queue simple remove $queueName

 

Auto Connect to Internet With DHCP Client – MikroTik Script RouterOS

The MikroTik RouterOS DHCP client may be enabled on any Ethernet-like interface at a time. The client will accept an address, netmask, default gateway, and two dns server addresses. The received IP address will be added to the interface with the respective netmask. The default gateway will be added to the routing table as a dynamic entry. Should the DHCP client be disabled or not renew an address, the dynamic default route will be removed. If there is already a default route installed prior the DHCP client obtains one, the route obtained by the DHCP client would be shown as invalid.

 

Add a DHCP client on ether1 (example: ether1 is a WAN/ISP) interface

 

/ip dhcp-client add interface=ether1 disabled=no

 

Auto Repair Passthrough In Mangle – MikroTik Script RouterOS

 

Script to solve passthrough errors in mikrotik mangle with many rules.

note: remember we understand the conditions of each mangle, because each setting will be different conditions, here I generally assume that all “mark-connection”, “mark-routing” uses passthrough = yes and “mark-packet” uses passthrough = no

 

foreach mrk in=(“packet”,”connection”, “routing”) do={

foreach i in=([/ip firewall mangle find where action=(“mark-” . $mrk)]) do={

:if ($mrk = “packet”) do={ 

local cmd (“ip firewall mangle set ” . $i . ” passthrough=no”)

:execute $cmd

}

:if ($mrk = “connection”) do={ 

local cmd (“ip firewall mangle set ” . $i . ” passthrough=yes”)

:execute $cmd

}

:if ($mrk = “routing”) do={ 

local cmd (“ip firewall mangle set ” . $i . ” passthrough=yes”)

:execute $cmd

}

}

}

 

Auto Backup Filename.backup and Send To Gmail – MikroTik Script RouterOS

How To Auto Backup Filename.backup and Send To Gmail

Setup Your mail first on Tool > Email

 

/tool e-mail set address=74.125.200.109 [email protected] password=xxxx port=587 start-tls=yes [email protected]

 

Input this script to Scheduler and you can set backup to gmail every week use interval like “7d 00:00:00”

 

#************************************************************

# BACKUP FILENAME.BACKUP AND SEND TO GMAIL BY BUANANET

#************************************************************

:global backupfile ([/system identity get name] . “-” . [/system clock get time])

/system backup save name=$backupfile

:delay 30s

:log info “backup being emailed”

/tool e-mail send to=”[email protected]” subject=([/system identity get name] . ” – “. [/system clock get time] . ” – ” . [/system clock get date] . “”) [email protected] file=(“$backupfile” . “.backup”)

:delay 30s

/file remove (“$backupfile” . “.backup”)

 

Automated Usage Script without usermanager – MikroTik RouterOS Script

Last Updated: 15th June 2009 Current version: v1.4

An updated version of this script is available at: MikroTik-RouterOS.com

If you have any questions you can also email me: admin ( at ) mikrotik-routeros ( dot ) com

 

Contents

 

1 Summary

2 Todo

3 Current known bugs

4 The Scheduler

4.1 Hourly

5 The Scripts

5.1 Script: overseer

5.2 Script: monthend

5.3 Script: usagereport

5.4 Script: monthlyreport

5.5 Script: manualusagereport

6 Final Notes

 

Summary

I wrote a usage tracking script based on the original Automated Billing Script

The way I run it is using a Mikrotik box setup to pass everything through transparently then I generated a Queue per IP address to keep track of the usage. On my test box (A PowerRouter 732) I currently have 3 class C blocks passing through with only 3% cpu (Multi CPU enabled).

This system is built for download-based billing only and will report the amount of downloads used by an IP address (or group if you setup a queue with multiple IP’s) each month. (This could easily be switched around thou)

If you use the alternate version of the monthend script you can set the scheduler to run overseer every 1hour without having to worry about multiple reports coming through.

Additional, I’ve since written a smaller manual script for accounts so they can run this at any time and have the usage reports emailed through (see the manual usage report script)

 

Todo

– ability to backup to a file on the mikrotik so it will count both data in the queue currently + data usage saved in the file (in case you lose power to the device or have to restart it at any time) Rethought – now saves downloaded data onto the end of comment, so scripts can also be exported if required. Page now updated to save data in the newly added comment field (I’ve been using this since v3.24)

– modifying the monthend script further so that it can only be triggered on the last hour of the last day of the month. This means you could then run the usage script hourly to get more frequent updates. This has been done, see original and alternate versions of the Monthend Script See below the script for details on how it works.

– modify the usage and monthly report scripts to use kbyte variables instead of bytes (this shouldn’t be any major issue thou, as the integer variables mikroik have allowed are 64bit, so a number can be as high as 9223372036854775807.

– allow sending to a client email address AND local support crew. Done: now you can specify a default email address in the usagereport (for sending to your support/accounts people) and the address in the queue becomes the client address to email, if you leave it blank eg: Client!50#!00#0000 instead of Client!50#[email protected]!00#0000 it will just skip sending the report email to the client but still send one to the support/accounts email address

 

Current known bugs

Monthend script will not complete (and won’t generate end of month reports) if you have starttime set to 00:00:00 for the hourly scheduler. Fix: Set startime to 00:30:00 or you can also run the end of month report script manually if you had missed

 

The Scheduler

Hourly

If you wish to poll hourly ensure that firstly you are using the new short version of the monthend script and also ensure that your start time isn’t 00:00:00 (setting it to 30m is ok like below) This ensures that the monthend time (being before >1:00am on the 1st of each month) is correctly matched and generates reports at the end of the month.

 

/system scheduler

add comment=”” disabled=no interval=1h name=Overseer on-event=”/system script run overseer” start-date=jan/01/1970 start-time=00:30:00

The Scripts

Script: overseer

Like the automated billing, this also has a calling script “overseer”

 

/code>:global found

 

/system script run monthend

 

:if ([$found] = “true”) do={/system script run monthlyreport; :log info “–Completed Monthly Report–“} else={ /system script run usagereport; :log info “–Completed Usage Report–“}

Script: monthend

At a set rollover date you want the system to run the monthend script to do the final site tally and reset all counters. By default this is set to run at the begining of each month (00 hour, 1st day) you can however change this to run on any day.

 

:local date

:local time

:local day

:local month

:local year

:local hour

:global found “”

 

:set date [/system clock get date]

:set time [/system clock get time]

:set day [:pick $date 4 6]

:set hour [:pick $time 0 2]

 

:if ([$day] = “01” ) do={ :if ([$hour] = “00” ) do={:set found “true” } else={ :set found “false” } } else={ :set found “false” }

Script: usagereport

The main usage report, takes the name of each queue and looks firstly for a hint that any data is contained in this. I have used ! to seperate the initial data block so If it finds a ! it will treat this name as data.

 

The data is then broken up from a name like this: Any Site name!50#[email protected]!00#0000 this then gives us $sitename (descriptive name) $gigs (gigabyte download limit) $email (address to email report to) $lastwarning (previous usage warning level) $bytesdownsaved (last total usage recording)

 

In previous versions of the script I had the values stored in the name, but now since it’s available the comment is a much better place to store this data. This also means you can give users static URL’s to access their own bandwidth graphs/queues.

 

:local content

:local i

:local sitename

:local gigs

:local email

:local megstotal

:local totalcurrent

:local bytesdowncurrent

:local bytesupcurrent

:local megsdowncurrent

:local megsupcurrent

:local percentage

:local lastwarning

:local warninglevel

:local warn

:local update

:local newwarning

:local bytesdownsaved

:local bytestotal

 

#Script based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling

#Details:

#This script checks all current simple queues and using values stored in the queue comment will allow you keep track of usage by each site

#The details stored in the queue are broken down and used to determine when a user should be sent a usage warning at 50 75 90 and 100%

#You can create/modify a new entry as long as you follow this format

#1) If you just want to name an entry you may do so like “XYZ Router” in the queue name

#2) If you want to determine a data limit, enter it like “sitename!gigabytelimit#emailaddress!00#0000” into the comment.

#3) If you just want to enter a comment on its own, you can do this so long as you don’t have an “!” in the field

#Breaking it down: sitename is a descriptive name, gigabyte limit is the monthy limit, email address is the address you want notified 

#00 is the last percentage warning level for this user, 0000 is the default value for a new data store

#This version created by Andrew Cox – www.accessplus.com.au

#v1.4 Updated 15/June/2009

:log info “—— Begining Daily Usage Reports ——-“

 

#For each queue in the list

:foreach i in=[/queue simple find comment !=””] do={

 

#Pull comment out of queue and divide up accordingly

:set content [/queue simple get $i comment]

 

#Determine variables from comment

#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-99)

:if ([:find $content “!”] != “”) do={

  :local pos1 [:find $content “!”]

  :local pos4 [:len $content]

  :local pos2 ([:find [:pick $content ($pos1+1) $pos4] “#”]+$pos1+1)

  :local pos3 ([:find [:pick $content ($pos2+1) $pos4] “!”]+$pos2)

  :set sitename [:pick $content 0 ($pos1)]

  :set gigs [:pick $content ($pos1+1) $pos2]

  :set email [:pick $content ($pos2+1) ($pos3+1)]

  :set totalcurrent [/queue simple get $i bytes]

  :set lastwarning [:pick $content ($pos3+2) ($pos3+4)]

  :local pos5 [:find $totalcurrent “/”]

  :local pos6 [:len $totalcurrent]

  :set bytesupcurrent ([:pick $totalcurrent 0 ($pos5)])

  :set bytesdowncurrent ([:pick $totalcurrent ($pos5+1) $pos6])

  :set megsupcurrent ($bytesupcurrent / 1048576)

  :set bytesdownsaved ([:pick $content ($pos3+5) $pos4])

  :set bytestotal ($bytesdowncurrent + $bytesdownsaved)

  :set megsdowncurrent ($bytestotal / 1048576)

 

#Begin calculating usage percentage

  :set percentage ( ( $bytestotal * 100) / ($gigs * 1073741824 ) )

  :log info “$sitename: $percentage%”

  :if ([$percentage] < 50) do={ :set warninglevel “00” }

  :if ([$percentage] > 50) do={

    :if ([$percentage] < 75) do={ :set warninglevel “50” }

    :if ([$percentage] > 75) do={ :set warninglevel “75” }

  }

  :if ([$percentage] > 75) do={

    :if ([$percentage] < 90) do={ :set warninglevel “75” }

    :if ([$percentage] > 90) do={ :set warninglevel “90” }

  }

  :if ([$percentage] > 90) do={

    :if ([$percentage] < 100) do={ :set warninglevel “90” }

    :if ([$percentage] > 100) do={ :set warninglevel “99” }

  }

 

# Parse warning necessity

 :if ([$warninglevel] > $lastwarning ) do={ :set warn “true” ; :set update “true” }

 :if ([$warninglevel] = $lastwarning ) do={ :set warn “false” ; :set update “false” }

 :if ([$warninglevel] < $lastwarning ) do={ :set warn “false” ; :set update “true” }

 

#Update Warning Levels

 :if ([$update] = true ) do={ :set newwarning $warninglevel } else={ :set newwarning $lastwarning }

 :if ([$warn] = true ) do={

#Check for email address in queue comment

 :if ([$email] != “” ) do={

  /tool e-mail send to=”$email” from=”[email protected]” server=”1.3.3.7″ subject=”$sitename: Usage at $percentage” body=”This message is to inform you of the current usage for $sitename

The current warning trigger is $warninglevel%.

 

This site has downloaded $megsdowncurrent MB, which is over $percentage% of the $gigs GB monthly download allowance.

 

This is an Automatically generated E-mail that is sent out when users reach 50%, 75%, 90% and 100% of their cap.

 

Traffic Monitor System,

[email protected]

}

#Send email to support/accounts also

  /tool e-mail send to=”[email protected]” from=”[email protected]” server=”1.3.3.7″ subject=”$sitename: Usage at $percentage” body=”Current usage for $sitename – trigger is $warninglevel%.

$megsdowncurrent MB, which is over $percentage% of the $gigs GB monthly download allowance.

Traffic Monitor System”

:log info “Sent Warning Level $warninglevel% to $email”

}

#Set new warning level on queue comment

/queue simple set $i comment=”$sitename!$gigs#$email!$newwarning#$bytestotal”

/queue simple reset-counters $i

}

}

 

Script: monthlyreport

Called by the overseer at the end of the month, this generates reports for Every site and then resets counters and the warning level back to 00

 

:local content

:local i

:local sitename

:local gigs

:local email

:local megstotal

:local totalcurrent

:local bytesdowncurrent

:local bytesupcurrent

:local megsdowncurrent

:local megsupcurrent

:local percentage

:local bytesdownsaved

:local bytesdowntotal

 

#Script based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling

#This version created by Andrew Cox – www.accessplus.com.au

#v1.4 Updated 15th June 2009

:log info “—— Begining Monthly Reports ——-“

#For each queue in the list

:foreach i in=[/queue simple find comment !=””] do={

 

#Pull comment out of queue and divide up accordingly

:set content [/queue simple get $i comment] 

 

#Determine variables from comment

#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-100)

:if ( [ :find $content “!” ] != “” ) do={

  :local pos1 [:find $content “!”]

  :local pos4 [:len $content]

  :local pos2 ([:find [:pick $content ($pos1+1) $pos4] “#”]+$pos1+1)

  :local pos3 ([:find [:pick $content ($pos2+1) $pos4] “!”]+$pos2)

  :set sitename [:pick $content 0 ($pos1)]

  :set gigs [:pick $content ($pos1+1) $pos2]

  :set email [:pick $content ($pos2+1) ($pos3+1)]

  :set totalcurrent [/queue simple get $i bytes]

  :local pos5 [:find $totalcurrent “/”]

  :local pos6 [:len $totalcurrent]

  :set bytesupcurrent ([:pick $totalcurrent 0 ($pos5)])

  :set bytesdowncurrent ([:pick $totalcurrent ($pos5+1) $pos6])

  :set megsupcurrent ($bytesupcurrent / 1048576)

  :set bytesdownsaved ([:pick $content ($pos3+5) $pos4])

  :set bytesdowntotal ($bytesdowncurrent + $bytesdownsaved)

  :set megsdowncurrent ($bytesdowntotal / 1048576)

 

#Begin calculating usage percentage

  :set percentage ( ( $bytesdowntotal * 100 ) / ( $gigs * 1073741824 ) )

  :log info “$sitename: $percentage%”

:if ([$email] != “” ) do={

/tool e-mail send to=$email [email protected] server=1.3.3.7 subject=”$sitename: Monthly Report” body=”This message is to inform you of the full monthly usage for $sitename

 

In this month this site has downloaded $megsdowncurrent MB, which is $percentage% of the $gigs GB monthly download allowance.

 

This is an Automatically generated E-mail that is sent out at the end of each month.

 

Traffic Monitor System,

[email protected]

}

#Send email to support/accounts also

  /tool e-mail send to=”[email protected]” from=”[email protected]” server=”1.3.3.7″ subject=”$sitename: Monthly Report” body=”Full monthly usage for $sitename

In this month this site has downloaded $megsdowncurrent MB, which is $percentage% of the $gigs GB monthly download allowance.

 

Traffic Monitor System,

[email protected]

Please report any errors in this message to [email protected]

:log info “Sent monthly report for $sitename to $email”

#Set warning level on queue comment back to 00 and reset counters

/queue simple set $i comment=”$sitename!$gigs#$email!00#0000″

/queue simple reset-counters $i

}

}

Script: manualusagereport

This script can be run manually at any time to send through the current usage report.

 

:local content

:local i

:local sitename

:local gigs

:local email

:local megstotal

:local totalcurrent

:local bytesdowncurrent

:local bytesupcurrent

:local megsdowncurrent

:local megsupcurrent

:local percentage

:local lastwarning

:local warninglevel

:local warn

:local update

:local newwarning

:local bytesdownsaved

:local bytestotal

:local text

:local combinedtext

:set combinedtext “”

 

#Scripts based on Automated billing script at http://wiki.mikrotik.com/wiki/AutomatedBilling

# This version created by Andrew Cox – www.mikrotik-routeros.com

#v1.4 Updated 15th June 2009

:log info “—— Begining Manual Usage Reports ——-“

 

#For each queue in the list

:foreach i in=[/queue simple find comment !=””] do={

 

#Pull comment out of queue and divide up accordingly

:set content [/queue simple get $i comment] 

 

#Determine variables from comment

#Format is: sitename ! gigsallowed # who-to-email ! last warning level(0-50-75-90-99) # data-used (0000)

:if ([:find $content “!”] != “”) do={

   :local pos1 [:find $content “!”]

   :local pos4 [:len $content]

   :local pos2 ([:find [:pick $content ($pos1+1) $pos4] “#”]+$pos1+1)

   :local pos3 ([:find [:pick $content ($pos2+1) $pos4] “!”]+$pos2)

   :set sitename [:pick $content 0 ($pos1)]

   :set gigs [:pick $content ($pos1+1) $pos2]

   :set email [:pick $content ($pos2+1) ($pos3+1)]

   :set totalcurrent [/queue simple get $i bytes]

   :set lastwarning [:pick $content ($pos3+2) ($pos3+4)]

   :local pos5 [:find $totalcurrent “/”]

   :local pos6 [:len $totalcurrent]

   :set bytesupcurrent ([:pick $totalcurrent 0 ($pos5)])

   :set bytesdowncurrent ([:pick $totalcurrent ($pos5+1) $pos6])

   :set megsupcurrent ($bytesupcurrent / 1048576)

   :set bytesdownsaved ([:pick $content ($pos3+5) $pos4])

   :set bytestotal ($bytesdowncurrent + $bytesdownsaved)

   :set megsdowncurrent ($bytestotal / 1048576)

 

#Begin calculating usage percentage

  :set percentage ( ( $bytestotal * 100) / ($gigs * 1073741824 ) )

  :log info “$sitename: $percentage% – $megsdowncurrent MB used – Allowance is $gigs GB”

  :set text “$combinedtext  $sitename: $percentage% – $megsdowncurrent MB used – Allowance is $gigs GB”

  :set combinedtext “$text”

 }

}

:log info “—— Ending Manual Usage Reports ——-“

:local time [/system clock get time]

/tool e-mail send server=”1.3.3.7″ from=”[email protected]” to=”[email protected]” subject=”Manual usage report” body=”Site Usage report – Runtime: $time

$text

 

Regards,

[email protected]

Final Notes

For those new to scripts, you can copy and paste these into winbox, but make sure that you at least remove the starting spacing from the comment lines (ones with #) if you don’t they aren’t treated as comments and will cause the script to error.

 

Quick trick to generate queues

 

#change the target address range to match what you want to generate.

:local x

:for x from 2 to 254 do={/queue simple add target-address=”10.2.100.$x” queue=”default/default”}

would generate queues for 10.0.0.2-10.0.0.254 for you.

 

note: the queue=default is important, as of v3.12 default-small queues with no child queues will be treated as if there was no queue at all (aka: unmonitored)

 

Allow Use Of ntp.org Pool Service For NTP – Mikrotik Script RouterOS

This script resolves the hostnames of two NTP servers, compares the result with the current NTP settings and changes the addresses if they’re different. This script is required as RouterOS does not allow hostnames to be used in the NTP configuration. Two scripts are used. The first defines some system variables which are used in other scripts and the second does the grunt work:

 

# System configuration script – “GlobalVars”

:put “Setting system globals”;

 

# System name

:global SYSname [/system identity get name];

 

# E-mail address to send notifications to

:global SYSsendemail “[email protected]”;

 

# E-mail address to send notifications from

:global SYSmyemail “[email protected]”;

 

# Mail server to use

:global SYSemailserver “1.2.3.4”;

 

# NTP pools to use (check www.pool.ntp.org)

:global SYSntpa “0.uk.pool.ntp.org”;

:global SYSntpb “1.uk.pool.ntp.org”;

# Check and set NTP servers – “setntppool”

 

# We need to use the following globals which must be defined here even

# though they are also defined in the script we call to set them.

:global SYSname;

:global SYSsendemail;

:global SYSmyemail;

:global SYSmyname;

:global SYSemailserver;

:global SYSntpa;

:global SYSntpb;

 

# Load the global variables with the system defaults

/system script run GlobalVars

 

# Resolve the two ntp pool hostnames

:local ntpipa [:resolve $SYSntpa];

:local ntpipb [:resolve $SYSntpb];

 

# Get the current settings

:local ntpcura [/system ntp client get primary-ntp];

:local ntpcurb [/system ntp client get secondary-ntp];

 

# Define a variable so we know if anything’s changed.

:local changea 0;

:local changeb 0;

 

# Debug output

:put (“Old: ” . $ntpcura . ” New: ” . $ntpipa);

:put (“Old: ” . $ntpcurb . ” New: ” . $ntpipb);

 

# Change primary if required

:if ($ntpipa != $ntpcura) do={

    :put “Changing primary NTP”;

    /system ntp client set primary-ntp=”$ntpipa”;

    :set changea 1;

    }

 

# Change secondary if required

:if ($ntpipb != $ntpcurb) do={

    :put “Changing secondary NTP”;

    /system ntp client set secondary-ntp=”$ntpipb”;

    :set changeb 1;

    }

 

# If we’ve made a change, send an e-mail to say so.

:if (($changea = 1) || ($changeb = 1)) do={

    :put “Sending e-mail.”;

    /tool e-mail send \

        to=$SYSsendemail \

        subject=($SYSname . ” NTP change”) \

        from=$SYSmyemail \

        server=$SYSemailserver \

        body=(“Your NTP servers have just been changed:Primary:Old: ” . $ntpcura . “New: ” \

          . $ntpipa . “SecondaryOld: ” . $ntpcurb . “New: ” . $ntpipb);

    }

 

 Scheduler entry:

 

/system scheduler add \

  comment=”Check and set NTP servers” \

  disabled=no \

  interval=12h \

  name=CheckNTPServers \

  on-event=setntppool \

  policy=read,write,test \

  start-date=jan/01/1970 \

  start-time=16:00:00

 

Auto upgrade script V3.x – Mikrotik Script RouterOS

One little script to upgrade RrouterBoards automatically.

-) fetch file from main router containing latest ROS version number;

-) get currently running version number;

-) extract minor and major version numbers and compare them;

-) if version fetched from main router is newer then download combined package directly from mikrotik.com

-) reboot.

At first you should create file containing newest version number on main router.

 

/file print file=”latestVer”;

/file set latestVer.txt content=”3.24″;

 

Now we are ready to run scripts on other routers:

 

#########################################################################

# download and upgrade

#########################################################################

# newest version

:local lMajor;

:local lMinor;

# current version

:local vMajor;

:local vMinor;

:local myVer [/system resource get version];

:for i from=0 to=([:len $myVer] – 1) do={  

:if ( [:pick $myVer $i] = “.”) do={ 

:set vMajor [:tonum [:pick $myVer 0 $i]]; 

:set vMinor [:tonum [:pick $myVer ($i + 1) [:len $myVer]]] ;

}

}

 

:if ($vMajor < 3) do={

:log warning “RouterOS version too old ($vMajor.$vMinor),  update script not compatible”;

} else={ 

#      detect platform (architecture-name is not available in older 3.x versions)

       :local platform [/system resource get architecture-name];

 

#      fetch latest version

       /tool fetch address=”172.16.0.1″ src-path=”latestVer.txt” user=”admin” password=”” mode=ftp;

       :local lVer [/file get latestVer.txt content];

 

:for i from=0 to=([:len $lVer] – 1) do={  

:if ( [:pick $lVer $i] = “.”) do={ 

:set lMajor [:tonum [:pick $lVer 0 $i]]; 

:set lMinor [:tonum [:pick $lVer ($i + 1) [:len $lVer]]] ;

}

}

 

:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={

:local pckgName “routeros-$platform-$lMajor.$lMinor.npk”;

/tool fetch address=[:resolve “www.mikrotik.com”] host=”www.mikrotik.com” mode=http src-path=”download/$pckgName”;

/system reboot;

} else={

                :log info “Upgrade_script: already latest version”;

        }

}

 

Audible signal test – Mikrotik Script RouterOS

Script for audible signal test on boards with beeper:

Code compatible with version 2.9:

 

:local beep “10ms”;

:local no “2400ms”;

:local 90 “1290ms”;

:local 85 “790ms”;

:local 80 “590ms”;

:local 77 “390ms”;

:local 74 “290ms”;

:local 71 “240ms”;

:local 68 “190ms”;

:local 65 “140ms”;

:local 62 “90ms”;

:local 59 “60ms”;

:local 56 “40ms”;

:local 53 “20ms”;

:local 50 “10ms”;

:for i from=1 to=100 do={

/interface wireless monitor wlan1 interval=1 do={

 :if ($signal-strength <= -90) do={

  :delay $no;

  }

 :if ($signal-strength <= -85 && $signal-strength > -90) do={

  :for i from=1 to=2 do={ :beep length=$beep; :delay $90; }

  }  

 :if ($signal-strength <= -80 && $signal-strength > -85) do={

  :for i from=1 to=3 do={ :beep length=$beep; :delay $85; }

  }

 :if ($signal-strength <= -77 && $signal-strength > -80) do={

  :for i from=1 to=4 do={ :beep length=$beep; :delay $80; }

  }  

 :if ($signal-strength <= -74 && $signal-strength > -77) do={

  :for i from=1 to=6 do={ :beep length=$beep; :delay $77; }

  }  

 :if ($signal-strength <= -71 && $signal-strength > -74) do={

  :for i from=1 to=8 do={ :beep length=$beep; :delay $74; }

  }  

 :if ($signal-strength <= -68 && $signal-strength > -71) do={

  :for i from=1 to=10 do={ :beep length=$beep; :delay $71; }

  }  

 :if ($signal-strength <= -65 && $signal-strength > -68) do={

  :for i from=1 to=12 do={ :beep length=$beep; :delay $68; }

  }  

 :if ($signal-strength <= -62 && $signal-strength > -65) do={

  :for i from=1 to=16 do={ :beep length=$beep; :delay $65; }

  }  

 :if ($signal-strength <= -59 && $signal-strength > -62) do={

  :for i from=1 to=24 do={ :beep length=$beep; :delay $62; }

  }  

 :if ($signal-strength <= -56 && $signal-strength > -59) do={

  :for i from=1 to=34 do={ :beep length=$beep; :delay $59; }

  }  

 :if ($signal-strength <= -53 && $signal-strength > -56) do={

  :for i from=1 to=48 do={ :beep length=$beep; :delay $56; }

  }

 :if ($signal-strength <= -50 && $signal-strength > -53) do={

  :for i from=1 to=80 do={ :beep length=$beep; :delay $53; }

  }  

 :if ($signal-strength <= -20 && $signal-strength > -50) do={

  :for i from=1 to=120 do={ :beep length=$beep; :delay $50; }

  }  

 }

}

 

Code compatible with version 3:

 

:local beep “10ms”;

:local no “2400ms”;

:local s90 “1290ms”;

:local s85 “790ms”;

:local s80 “590ms”;

:local s77 “390ms”;

:local s74 “290ms”;

:local s71 “240ms”;

:local s68 “190ms”;

:local s65 “140ms”;

:local s62 “90ms”;

:local s59 “60ms”;

:local s56 “40ms”;

:local s53 “20ms”;

:local s50 “10ms”;

:for i from=1 to=100 do={

/interface wireless monitor wlan1 interval=1 do={

 :if ($”signal-strength” <= -90) do={

  :delay $no;

  }

 :if ($”signal-strength” <= -85 && $”signal-strength” > -90) do={

  :for i from=1 to=2 do={ :beep length=$beep; :delay $s90; }

  }  

 :if ($”signal-strength” <= -80 && $”signal-strength” > -85) do={

  :for i from=1 to=3 do={ :beep length=$beep; :delay $s85; }

  }

 :if ($”signal-strength” <= -77 && $”signal-strength” > -80) do={

  :for i from=1 to=4 do={ :beep length=$beep; :delay $s80; }

  }  

 :if ($”signal-strength” <= -74 && $”signal-strength” > -77) do={

  :for i from=1 to=6 do={ :beep length=$beep; :delay $s77; }

  }  

 :if ($”signal-strength” <= -71 && $”signal-strength” > -74) do={

  :for i from=1 to=8 do={ :beep length=$beep; :delay $s74; }

  }  

 :if ($”signal-strength” <= -68 && $”signal-strength” > -71) do={

  :for i from=1 to=10 do={ :beep length=$beep; :delay $s71; }

  }  

 :if ($”signal-strength” <= -65 && $”signal-strength” > -68) do={

  :for i from=1 to=12 do={ :beep length=$beep; :delay $s68; }

  }  

 :if ($”signal-strength” <= -62 && $”signal-strength” > -65) do={

  :for i from=1 to=16 do={ :beep length=$beep; :delay $s65; }

  }  

 :if ($”signal-strength” <= -59 && $”signal-strength” > -62) do={

  :for i from=1 to=24 do={ :beep length=$beep; :delay $s62; }

  }  

 :if ($”signal-strength” <= -56 && $”signal-strength” > -59) do={

  :for i from=1 to=34 do={ :beep length=$beep; :delay $s59; }

  }  

 :if ($”signal-strength” <= -53 && $”signal-strength” > -56) do={

  :for i from=1 to=48 do={ :beep length=$beep; :delay $s56; }

  }

 :if ($”signal-strength” <= -50 && $”signal-strength” > -53) do={

  :for i from=1 to=80 do={ :beep length=$beep; :delay $s53; }

  }  

 :if ($”signal-strength” <= -20 && $”signal-strength” > -50) do={

  :for i from=1 to=120 do={ :beep length=$beep; :delay $s50; }

  }  

 }

}

 

Code for RouterBoard 411 with led and sound aligment:

 

:local beep “10ms”;

:local no “2400ms”;

:local s90 “1290ms”;

:local s85 “790ms”;

:local s80 “590ms”;

:local s77 “390ms”;

:local s74 “290ms”;

:local s71 “240ms”;

:local s68 “190ms”;

:local s65 “140ms”;

:local s62 “90ms”;

:local s59 “60ms”;

:local s56 “40ms”;

:local s53 “20ms”;

:local s50 “10ms”;

:for i from=1 to=100 do={

/interface wireless monitor wlan1 interval=1 do={

 :if ($”signal-strength” <= -90) do={

  :delay $no;

  }

 :if ($”signal-strength” <= -85 && $”signal-strength” > -90) do={

  :for i from=1 to=2 do={ :beep length=$beep; :delay $s90; :led led1=yes led2=no led3=no led4=no led5=no }

  }  

 :if ($”signal-strength” <= -80 && $”signal-strength” > -85) do={

  :for i from=1 to=3 do={ :beep length=$beep; :delay $s85; :led led1=yes led2=no led3=no led4=no led5=no }

  }

 :if ($”signal-strength” <= -77 && $”signal-strength” > -80) do={

  :for i from=1 to=4 do={ :beep length=$beep; :delay $s80; :led led1=yes led2=yes led3=no led4=no led5=no }

  }  

 :if ($”signal-strength” <= -74 && $”signal-strength” > -77) do={

  :for i from=1 to=6 do={ :beep length=$beep; :delay $s77; :led led1=yes led2=yes led3=no led4=no led5=no }

  }  

 :if ($”signal-strength” <= -71 && $”signal-strength” > -74) do={

  :for i from=1 to=8 do={ :beep length=$beep; :delay $s74; :led led1=yes led2=yes led3=yes led4=no led5=no }

  }  

 :if ($”signal-strength” <= -68 && $”signal-strength” > -71) do={

  :for i from=1 to=10 do={ :beep length=$beep; :delay $s71; :led led1=yes led2=yes led3=yes led4=no led5=no }

  }  

 :if ($”signal-strength” <= -65 && $”signal-strength” > -68) do={

  :for i from=1 to=12 do={ :beep length=$beep; :delay $s68; :led led1=yes led2=yes led3=yes led4=yes led5=no }

  }  

 :if ($”signal-strength” <= -62 && $”signal-strength” > -65) do={

  :for i from=1 to=16 do={ :beep length=$beep; :delay $s65; :led led1=yes led2=yes led3=yes led4=yes led5=no }

  }  

 :if ($”signal-strength” <= -59 && $”signal-strength” > -62) do={

  :for i from=1 to=24 do={ :beep length=$beep; :delay $s62; :led led1=yes led2=yes led3=yes led4=yes led5=no }

  }  

 :if ($”signal-strength” <= -56 && $”signal-strength” > -59) do={

  :for i from=1 to=34 do={ :beep length=$beep; :delay $s59; :led led1=yes led2=yes led3=yes led4=yes led5=yes }

  }  

 :if ($”signal-strength” <= -53 && $”signal-strength” > -56) do={

  :for i from=1 to=48 do={ :beep length=$beep; :delay $s56; :led led1=yes led2=yes led3=yes led4=yes led5=yes }

  }

 :if ($”signal-strength” <= -50 && $”signal-strength” > -53) do={

  :for i from=1 to=80 do={ :beep length=$beep; :delay $s53; :led led1=yes led2=yes led3=yes led4=yes led5=yes }

  }  

 :if ($”signal-strength” <= -20 && $”signal-strength” > -50) do={

  :for i from=1 to=120 do={ :beep length=$beep; :delay $s50; :led led1=yes led2=yes led3=yes led4=yes led5=yes }

  }  

 }

}

 

A Bit of Sounds – Mikrotik Script RouterOS

Part One: SQUAWK

The scripts below are based on SQUAWK program (C) 1987 Merlin R. Null.

 

# SQUAWK Chang

 :for j from=1 to=4 step=1 do={

   :for i from=2000 to=50 step=-400 do={

     :beep frequency=$i length=11ms;

     :delay 11ms;

   }

   :for i from=800 to=2000 step=400 do={

     :beep frequency=$i length=11ms;

     :delay 11ms;

   }

 }

 

  

# SQUAWK Coo

 :for i from=0 to=150 step=10 do={

   :beep frequency=(1295 – i) length=22ms;

   :delay 22ms;

   :beep frequency=(1095 + i) length=22ms;

   :delay 22ms;

 }

 

  

# SQUAWK Oh!

 :for i from=800 to=2000 step=100 do={

   :beep frequency=$i length=11ms;

   :delay 11ms;

 }

 :for i from=2000 to=50 step=-100 do={

   :beep frequency=$i length=11ms;

   :delay 11ms;

 }

 

  

# SQUAWK Phone 1

 :for i from=1 to=10 step=1 do={

   :beep frequency=1195 length=22ms;

   :delay 22ms;

   :beep frequency=2571 length=22ms;

   :delay 22ms;

 }

 

 

# SQUAWK Siren

 :for i from=1 to=3 step=1 do={

   :beep frequency=550 length=494ms;

   :delay 494ms;

   :beep frequency=400 length=494ms;

   :delay 494ms;

 }

 

  

# SQUAWK Space 1

 :for i from=1000 to=40 step=-20 do={

   :beep frequency=$i length=11ms;

   :delay 11ms;

 }

 

 

# SQUAWK Space 2

 :for i from=10000 to=500 step=-500 do={

   :beep frequency=$i length=11ms;

   :delay 11ms;

 }

 

  

# Phone Call

 

 :for i from=1 to=10 do={

   /system script run “SQUAWK Phone 1”;

   :delay 400ms;

   /system script run “SQUAWK Phone 1”;

   :delay 2000ms;

 }

 

Part Two: Adams

The scripts below are based on the code from Lee Adams’ book “Grafik, Animation, Simulation fur Personalcomputer” (ISBN 3890905722, Markt&Technik, 1989).

 

# Adams Fanfare

 :for t from=1200 to=350 step=-50 do={

   :beep frequency=$t length=33ms;

   :delay 33ms;

 }

 

  

# Adams Larm

 :for t1 from=1 to=10 step=1 do={

   :for t2 from=300 to=1800 step=40 do={

     :beep frequency=$t2 length=11ms;

     :delay 11ms;

   }

 }

 

  

# Adams Maschinengewehr

 :for t from=1 to=20 step=1 do={

   :beep frequency=40 length=33ms;

   :delay 33ms;

   :delay 55ms;

 }

 

 

# Adams Telefone

 :for t1 from=1 to=4 step=1 do={

   :for t2 from=1 to=25 step=1 do={

     :beep frequency=540 length=33ms;

     :delay 33ms;

     :beep frequency=650 length=27ms;

     :delay 27ms;

   }

   :delay 2000ms;

 }

 

 

# Adams Tonarkade

 :for t1 from=1 to=8 step=1 do={

     :for t2 from=600 to=750 step=8 do={

     :beep frequency=$t2 length=11ms;

     :delay 11ms;

   }

 }

 

 

# Adams Tonarkade 2

 :for t from=1250 to=600 step=-8 do={

   :beep frequency=$t length=11ms;

   :delay 11ms;

 }

 

Part Three: Miklavcic

The scripts below are based on the code from http://snipplr.com/view/9220/simple-tic-tac-toe/

 

# Miklavcic Sad

 :beep frequency=784 length=500ms;

 :delay 500ms;

 

 :beep frequency=738 length=500ms;

 :delay 500ms;

 

 :beep frequency=684 length=500ms;

 :delay 500ms;

 

 :beep frequency=644 length=1000ms;

 :delay 1000ms;

 

# Miklavcic Victory

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=659 length=700ms;

 :delay 700ms;

 

 :beep frequency=784 length=500ms;

 :delay 500ms;

 

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=523 length=200ms;

 :delay 1000ms;

 

 :beep frequency=659 length=700ms;

 :delay 700ms;

 

 :beep frequency=784 length=500ms;

 :delay 800ms;

 

 :beep frequency=784 length=400ms;

 :delay 400ms;

 

 :beep frequency=884 length=200ms;

 :delay 200ms;

 

 :beep frequency=784 length=200ms;

 :delay 200ms;

 

 :beep frequency=687 length=200ms;

 :delay 200ms;

 

 :beep frequency=659 length=200ms;

 :delay 200ms;

 

 :beep frequency=579 length=200ms;

 :delay 200ms;

 

 :beep frequency=519 length=400ms;

 :delay 400ms;

 

 

# Part Z: Assorted Sounds

# Sound 1

 

 :beep frequency=600 length=165ms;

 :delay 165ms;

 

 :beep frequency=50 length=83ms;

 :delay 83ms;

 

 :beep frequency=600 length=165ms;

 :delay 165ms;

 

 :beep frequency=50 length=83ms;

 :delay 83ms;

 

 :beep frequency=650 length=165ms;

 :delay 165ms;

 

 :beep frequency=600 length=165ms;

 :delay 165ms;

 

 :beep frequency=50 length=83ms;

 :delay 83ms;

 

 :beep frequency=600 length=165ms;

 :delay 165ms;

 

 :beep frequency=700 length=275ms;

 :delay 275ms;

 

 :beep frequency=800 length=275ms;

 :delay 275ms;

 

 :beep frequency=900 length=110ms;

 :delay 110ms;

 

Add a Data Limit To Trial Hotspot Users – MikroTik Script RouterOS

The following script allows you to assign a data limit to trial hotspot users and

  1. a) have them kicked offline upon reaching this limit
  2. b) create a temporary local user to stop them from logging back in again

This is a feature which is not available via the current hotspot settings, so I decided to script it into existence. Enjoy!

Script to check users for those over the limit:

Make a scheduler entry to run this every X minutes, I’d recommend every 5-10 minutes.

 

#Download limit in MB

:local downquotamb “50”

# Do not modify anything below this line #

:local downquota [$downquotamb * 1000]

:local counter

:local datadown

:local username

:local macaddress

:foreach counter in=[/ip hotspot active find ] do={

:set datadown [/ip hotspot active get $counter bytes-out]

:if ($datadown>$downquota) do={

:set username [/ip hotspot active get $counter user]

:set macaddress [/ip hotspot active get $counter mac-address]

/ip hotspot user remove [/ip hotspot user find where name=$username]

/ip hotspot user add name=$username limit-bytes-out=$downquota mac-address=$macaddress

/ip hotspot active remove $counter

:log info “Logged out $username – Reached download quota”

}}

 

Script to clear all manually created user accounts; this can be done hourly, daily or weekly depending on your requirements.

 

:foreach counter in=[/ip hotspot user find ] do={/ip hotspot user remove \$counter}

 

Notes: 

You can modify how often you want each of the script

 

Auto Update RouterOS Package From Script – MikroTik Script RouterOS

If you administer only a few MikroTik devices, you can manually update them one by one using the WinBox tool. This is a very easy task if you install only the long-term versions. That version is rarely updated and contains only the major bug fixes.

In case that you have larger number of devices under your control, you will probably want more automation. The good news is that you can use the magic of the command line to perform such task. This means that you can also write the update script.

Contrary to the scenario with your local update source point, if your routers are independent to each other and on the separate Internet links, you will want to use the different process to update them all at once.

 

# Simple RouterOS upgrade script

# version 1 (09.03.2020)

# written by Srdjan Stanisic 

# go to the update context

/system package update 

# set the channel

set channel=long-term

# check for updates

check-for-updates

# we can log the status

:log info “$[get status]”

#

# check for the new version

# if there is a newer version, then download it and reboot the router

# you can omit automatic reboot and send email instead

# additionally, we can omit the ELSE part

:if (installed-version != latest-version) do={

    download;

} else={

    :put “System is already up to date”

}

 

This script is ready to be used. Copy it into the text file and save it with .rsc extension

 

ARP Table To Dynamic Simple Queue – MikroTik Script RouterOS

Dynamic Simple Queue Script (ARP Table)

Ideas

  • Using simple queues to limit any traffic (or could be a packet mark) from specific target IP
  • Only make simple queues rule for any active IP on the network (taken from ARP table)
  • Utilize MikroTik’sadvantage to runs script and task scheduling to do the job.

How to use

  • Create your mangle
  • Customize based on your specific need/network configuration•Drag-drop-import

How It Works

  1. The script will make a parent queue(i)and a catch-all rule(ii)for our workaround with all parameter which we’ve already set.
  2. Takes all IP addresses and MAC address with specified filter (interface) from /iparptable.
  3. Removes all dynamic rules previously created, if available. Then creates simple queue rules using parameters we’ve already set.
  4. Delay for specified time (default is 60 secs) and re-run the steps from number 2.5.The scheduler at /system scheduler checks and ensures that the script is running in the background.

 

# System Script

/system script

job remove [find script=”limitDynamic”];

remove [find name=”limitDynamic”];

add name=”limitDynamic” source={

:local filterARP “br-local”;

:local targetAddress “192.168.10.0/24”;

:local limitClient “3M”;

:local limitParent “30M”;

:local parentLimit “0-Parent”;

:local packetMark “client.p”;

:local delay “60s”;

:local enabled true;

:local enableLog true;

/queue simple

:if ($enabled) do={

:if ([find name=($parentLimit)] = “”) do={ add name=($parentLimit) packet-mark=$packetMark target=$targetAddress max-limit=($limitParent.”/”.$limitParent);}

:if ([find name=($parentLimit.”-all”)] = “”) do={ add name=($parentLimit.”-all”) parent=$parentLimit packet-mark=$packetMark target=$targetAddress max-limit=($limitParent.”/”.$limitParent); }

}

:while (true) do={

:local arp [:toarray [/ip arp print as-value where dynamic && interface=$filterARP ]];

:local queue [:toarray [/queue simple print as-value]];

:if ($enableLog) do={ :log warning message= “Removing any dynamic queue entry …”;}

:if ($enabled) do={ /queue simple remove [find (parent=$parentLimit) && (name!=($parentLimit.”-all”))];}

:if ($enableLog) do={ :log warning message= “All dynamic queue removed.”; :log warning message= “Adding new dynamic queue entry …”;}

:foreach a in=$arp do={

:local ip ($a->”address”);

:local zz ($a->”mac-address”);

:if ($enabled) do={/queue simple add name=($zz) target=$ip max-limit=($limitClient.”/”.$limitClient) parent=$parentLimit packet-mark=$packetMark place-before=($parentLimit.”-all”);}

}

:if ($enableLog) do={ :log warning message= “Finished adding”; :log warning message= “Running delay”;}

:delay $delay;

}

}

:execute “/system script run limitDynamic;”

 

# system scheduler

/system scheduler

remove [find name=”limitDynamic”];

add name=limitDynamic interval=10m on-event={ :if ([:len [/system script job find script=limitDynamic]] = 0 ) do={/system script run limitDynamic;}}

/file remove [find name=”limit-dynamic-mum.rsc”];

 

Add Static DHCP Leases to ARP List – MikroTik Script RouterOS

This script will upate the ARP List with all static, enabled leases. It makes the changes in place (i.e. it doesn’t delete all the ARP entries first) to minimize disruptions. Limitation of the script is that the interface for the ARP entry needs to be hardcoded for now.

 

:local wanInterfaceName “ether1_wan”;

# Remove ARP entries that do not have static DHCP leases or are disabled

:foreach arpId in=[/ip arp find] do={

#Don’t remove the dynamic entry on the WAN side

  :if ([/ip arp get $arpId interface] != $wanInterfaceName) do={

#If there is no matching entry in the lease table remove it

:local mac [/ip arp get $arpId mac-address];

:local leaseId [/ip dhcp-server lease find where mac-address=$mac];

:if ($leaseId=””) do={

/ip arp remove $arpId;

:log info (“Removing old ARP entry”);

} else={

:if ([/ip dhcp-server lease get $leaseId disabled]) do={

/ip arp remove $arpId;

:log info (“Removing disabled ARP entry”);

}}}}

:foreach leaseId in=[/ip dhcp-server lease find where !dynamic] do={

:local mac  [/ip dhcp-server lease get $leaseId mac-address];

:local arpId [/ip arp find where mac-address=$mac];

:if ($arpId=”” && ![/ip dhcp-server lease get $leaseId disabled]) do={

:local ip [/ip dhcp-server lease get $leaseId address];

:local comment  [/ip dhcp-server lease get $leaseId comment];

#interface should not be hard coded but couldn’t figure out what to do

:local interface lan_wlan_bridge;

/ip arp add address= $ip mac-address= $mac comment= $comment interface= $interface;

:log info (“Adding new ARP entry”);

}

}

 

Alignment Script that “reads back” RSSI with Beeps – MikroTik Script RouterOS

How To Alignment Script that “reads back” RSSI with Beeps..

 

#

# Mikrotik RB411/433 “RSSI Readback” alignment script

# Based off script by Mark Shumate Feb 2009

# Modified by Randy Cosby June 2009

#

# NOTE: This script may work on other platforms, I

# don’t have anything but RB411/433 here in front of

# me. The Beeps will probably work on practically any

# wireless CPE type Routerboard, but maybe the script

# would have to be edited? 

#

 

# default delaytime

:local lnsdelaytime 230ms;

 

# name of wireless interface to monitor (default wlan1)

:local lnsintname “wlan1”;

:local lnsbeepfreq 800;

 

# base freq (as in pitch) of tens digit beep 

:local tensbeepfreq 1200;

#  base freq (as in pitch) of ones digit beep 

:local onesbeepfreq 1100;

 

# The (veery approximate, heh) running time of the script

# is set here. I am too lazy right now to do this a

# better way…besides, who cares if the thing Beeps 

#  a couple extra minutes right?!? 🙂

:local lnsrunningtime 10m;

 

# Here, we set how long the script will beep. NOTE that

# startup/shutdown tones will still be played.

:local lnsbeeptime 10m;

 

# figure out beep cutoff time

:local lnsrunbeepdiff;

:set lnsrunbeepdiff ($lnsrunningtime – $lnsbeeptime);

 

# play starting tones

:delay 150ms;

:beep frequency=($lnsbeepfreq – 300) length=150ms;

:delay 150ms;

:beep frequency=($lnsbeepfreq – 200) length=150ms;

:delay 550ms;

 

# main monitoring cycle

:while ($lnsrunningtime > 0s) do={

 /interface wireless monitor “$lnsintname” once do={

     :put “Monitoring….”;

:if ($”status” = “connected-to-ess”) do={

#:if ($”status” = “searching-for-network”) do={

 

     :local rssi ($”signal-strength”);

#     :local rssi -60;

     :put $”signal-strength”;

     :local tensBeeps (tonum( $rssi / 10 ) * -1 );

     :put $tensBeeps;

     :local onesBeeps (($rssi*-1) – ($tensBeeps * 10))

     :put $onesBeeps;

     :for i from=1 to=($tensBeeps) do={

     :beep frequency=(-($rssi*$rssi)/10+$tensbeepfreq) length=($lnsdelaytime / 2);

     :delay $lnsdelaytime;

     :set lnsrunningtime ($lnsrunningtime – $lnsdelaytime);

 

     }

     :delay 400ms;

     :set lnsrunningtime ($lnsrunningtime – 400ms);

     :if ($onesBeeps = 0) do={

             :beep frequency=(-($rssi * $rssi)/10 + $onesbeepfreq) length=($lnsdelaytime*2);

             :delay $lnsdelaytime;

             :set lnsrunningtime ($lnsrunningtime – ($lnsdelaytime));

            } else={

     :for i from=1 to=($onesBeeps) do={

     :beep frequency=(-($rssi * $rssi)/10 + $onesbeepfreq) length=($lnsdelaytime / 2);

     :delay $lnsdelaytime;    

     :set lnsrunningtime ($lnsrunningtime – $lnsdelaytime);

 

      }

     }

     :delay 1s;

            } else={

    :if ($”status” = “searching-for-network”) do={

      

       :delay 200ms;

      :if ($lnsrunningtime > $lnsrunbeepdiff) do={

        :beep frequency=$lnsbeepfreq length=150ms;

      }

       :delay 200ms;

       :if ($lnsrunningtime > $lnsrunbeepdiff) do={

         :beep frequency=($lnsbeepfreq + 100) length=125ms;

       }

       :delay 150ms;

       :if ($lnsrunningtime > $lnsrunbeepdiff) do={

         :beep frequency=($lnsbeepfreq + 200) length=100ms;

       }

       :delay 300ms;

       :set lnsrunningtime ($lnsrunningtime – 750ms);

       } else={

       

       :if ($lnsrunningtime > $lnsrunbeepdiff) do={

         :beep frequency=($lnsbeepfreq – 150) length=150ms;

       }

       :delay 150ms;

       :if ($lnsrunningtime > $lnsrunbeepdiff) do={

         :beep frequency=($lnsbeepfreq – 350) length=100ms;

       }

       :delay 1550ms;

       

     }

   }

 }

#:put $lnsrunningtime;

#:set lnsrunningtime (totime($lnsrunningtime));

#:set lnsrunningtime (“$lnsrunningtime” – “$lnsdelaytime”);

:put $lnsrunningtime;

}

# shut off LEDs, play shutdown tones

:beep frequency=($lnsbeepfreq – 200) length=150ms;

:delay 150ms;

:beep frequency=($lnsbeepfreq – 300) length=150ms;

:delay 150ms;

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *