MikroTik RouterOS Scripts for various use and shared among different projects. Repository contains ready to use scripts as well functions ready to use in larger projects. Check also another repository with scripts related strictly to MikroTik CAPsMAN automation đź”— CAPsMAN Automation Scripts.
- âś… RouterOS v6.40 or higher
- âś… MikroTik CRS or CCR with LCD for RouterOS_LCD_Change.rsc
Use the following scripts to make your RouterOS management easier or use them in various larger scripts or projects :+1:
This script creates two files via RouterOS scheduler as well creates FTP user and group:
- .backup file
- .rsc file
Automated download of all latest RouterOS standard packages. Tool recommended for CAPsMANs and DUDE servers
Wrapper to append array elements
Checks if latest firmware is available. Installs it and sends email notification
Example
$AutoFirmwareUpgrade smtpServer=smtpServer smtpPort=smtpPort domain=example.com \
[email protected];
Checks if latest package is available. Downloads it, installs and sends email notification
Example
$PackageAutoDownload userName=userName password=password packagePath=path \
smtpServer=ipAddress smtpPort=poty [email protected] \
[email protected];
Creates new backup file and uploads it to MikroTik Cloud
Example
$CloudBackup password=password;
RouterOS function that creates directory with defined name in the system. Can be used just to create directory or be a part of larger project.
Example
$CreateDirecotry userName=UserName password=Password directoryName=DirectoryName;
Simple setup for DUAL WAN failover. Main WAN must be commented as WAN1. Secondary WAN must be commented as WAN2
RouterOS function for log messages filtering based on message or time match stored in chosen output.
Example
$LogFilter;
RouterOS function sending mail alert if log entry matches message criteria.
Example
$LogToAlert message="message" fileName="fileName" smtpServer=smtpServer smtpPort=smtpPort domain="@example.com" \
recipient="[email protected]";
RouterOS function to send email via SMTP server. Function contains all common email fields like to, cc, subject, body and more. Function can be called itself in RouterOS or by other script.
Example
$SendEmail smtpServer=SMTPServer smtpPort=SMTPPort from=From to=To subject=Subject body=Body;
RouterOS function adding log entry if file was added or removed.
Example
$FileToLog;
RouterOS function changing LCD mode from dark to light and vice versa based on schedule setup.
Example
$ChangeLcd lightModeStartTime="08:00:00" darkModeStartTime="17:00:00";
RouterOS function generating mail alert if disk space is below defined treshhold.
Example
$LowDiskSpace treshhold=free_disk_space_in_%;
Creates RouterOS backup and config file and sends them via email
Example
$MailBackup configName=configName backupName=backupName smtpServer=smtpServer smtpPort=smtpPort [email protected] \
[email protected];
Removes files by specific name or file extansion
Example
$FileScreening keyWord=".txt";
Formats RouterOS additional drive
Example
$FormatDrive drive=0 fileSystem=ext3 label=data;
Modulo function.
Example
$Modulo number=number_to_be_devided modulo=modulo_value;
Port Knock from RouterOS
Example
:global knockBase {"sourceIP1"="port23"; \
"sourceIP2"="port22" \
};
$PortKnock base=$knockBase destinationAddress=destinationIP;
ARP/RARP Function (shortange syntax)
Example
$R_ARP mode=mode;
Sends Radius statistics via email
Example
$RadiusMonitor smtpServer=smtpServer smtpPort=smtpPort domain="@example.com" recipient="[email protected]";
Renews RouterOS License
Example
$RenewLicense account=account password=password level=level;
Loads function to RouterOS environment
Example
$LoadScript scriptName=scriptName.rsc;
Generates 6 char string based on dictionary
Example
$GenerateString;
Resets interface if particular IP does not respond
Example
$ResetInterface ipAddress=ipAddress_To_Monitor interfaceName=interface_name;
Fetches script from git to RouterOS directory
Example
$FetchScript url="https://example.repo.com" destinationPath="FolderName" destinationFileName="ScriptName"
$FetchScript url="https://example.repo.com" destinationPath="FolderName" destinationFileName="ScriptName" isRun=true
$FetchScript url="https://example.repo.com" destinationPath="FolderName" destinationFileName="ScriptName" isSchedule=true\
interval="24" taskName="TaskName" startTime="startup"
Substrings variable
Example
$Substring findMode=true string="string" signA="A" signB "b";
After defined number of logon failure attempts in 1 hour sends email alert and blocks source IP on firewall
Example
$UserAlert message="message" treshhold=3 fileName="fileName" smtpServer=smtpServer smtpPort=smtpPort domain="@i4e.com.bd" \
recipient="[email protected]";
Creates backup files and sends them via FTP to FTP server
Example
$FTPBackup configName=configName backupName=backupName smtpServer=smtpServer smtpPort=smtpPort [email protected] \
[email protected] destPath=destPath ftpUser=user ftpPassword=password ftpServer=ftpserver;
Function template that I use
Disconnects all PPP active sessions at once
Example
$DisconnectPPPActveSessions;
Recreates bridge if broken or misconfigured
- Lupael