wireless on off with mode button
search tag # rextended wireless on off with mode button
For 6.46.8 / 6.47.9 and up
This disable/enable all wifi on board,
the “master” is wlan1, all the others change accordingly
this is the script to put on “on-event” event on mode button and change user-led status accordingly (wi-fi led, if present are turnded off/on automatically)
/system leds
:if ([:len [find where leds=user-led]] < 1) do={add leds=user-led type=on}
:log info "Premuto Pulsante"
/interface wireless
:if ([get [find defaul…
create directory and subdirectory
search tag # rextended create directory and subdirectory
the function return an array for check on calling script if the path are created or not (and why not)
if the result ($results->0) containing OK, on ($results->1) are present the name of folder/path created
35 lines and also with sanitizing input and “flash” folder on consideration
:global createpath do={
:global createpath
:if ([/system resource get architecture-name] = "smips") do={:return [:toarray ("ERROR,SMIPS")]}
:if (…
mac ping results saved on variable
search tag # rextended mac ping results
Now you can, see this example:
/file remove [find where name="testmacping.txt"]
{
:local jobid [:execute file=testmacping.txt script="/ping address=64:D1:54:55:FF:CC arp-ping=yes interface=bridge count=10"]
:put "Waiting the end of process for file testmacping.txt to be ready, max 20 seconds..."
:global Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < 20)) do={
:set Gltesec ($Gltesec + 1)
…
Put snmp-get value on variable
search tag # rextended read snmp put value on variable
After 4 years the solution…
Just ask…
I just invented that method.
One example:
/file remove [find where name="testgetsnmp.txt"]
{
:local jobid [:execute file=testgetsnmp.txt \
script="/tool snmp-get tries=3 try-timeout=3s address=192.168.0.1 port=161 version=2c \
community=public oid=1.3.6.1.4.1.14988.1.1.3.8.0"]
:put "Waiting the end of process for file testgetsnmp.txt to be ready, max 20 seconds..."
:globa…
Convert character to uppercase or lowercase
search tag # rextended lowercase uppercase chr2lcase chr2ucase
Functions to convert single character on lowercase and to uppercase.
Any other character passed remain unchanged.
:global chr2lcase do={
:local charsString ""
:for x from=0 to=15 step=1 do={ :for y from=0 to=15 step=1 do={
:local tmpHex "$[:pick "0123456789ABCDEF" $x ($x+1)]$[:pick "0123456789ABCDEF" $y ($y+1)]"
:set $charsString "$charsString$[[:parse "(\"\\$tmpHex\")"]]"
} }
:local chrValue [:find…
UNIX time Epoch, day of the week, ISO:8601 date
Do you find this script useful?
poll
Hi there.
Since version 6.2 I try to make a script to compute the UNIX time (epoch time / posix time) from RB current date/time.
The script contains 2 functions: first one is JD which calculates Julian Days for specified date and the second one calculates the unix time based on difference between Julian Days and Julian date of ‘jan/01/1970’.
I guess is not flawless, but here it is :
:global fncJD do={
:local months [:toarray "jan,feb,mar,ap…
Import IP or IP prefix from file
Hello.
I’m struggling with getting to run script that I found to import IP addresses from file and adding them to my address list.
Idea is to fetch file with all official country IP addresses from Web page (file name is “local.net ”) and add them to list.
Fetching script is working fine, bet when I run the script to add IP to list I get only first number added to my address list.
[Screenshot 2020-09-17 at 11.27.53.png]
Also, is there “4096 byte read/write limit” workaround?
Maybe there is s…
How to download only one piece of file at a time with /tool fetch and put it inside a variable
search tag # rextended load split large file
While waiting for MikroTik to implement the ability to read a file larger than 64KB (64512B) as a value for a variable…
I found a way to download only one piece of file at a time with /tool fetch and put it inside a variable
For example this file is 942KB, too big to put it on one variable to be processed to one script that add to one address-list the IP contained.
https://www.iwik.org/ipcountry/US.cidr
but I can read it like 15 separate file…
Decode USSD hexstr2chrstr hexadecimal string to char string
search tag # rextended hexstr2chrstr hexadecimal string to char string
I write now a function to convert directly on routerboard based on my hex2chr:
http://forum.mikrotik.com/t/how-to-convert-a-hex-value-to-a-char/97913/9
:global hexstr2chrstr do={
:local hexstr $1
:local hexlen [:len $hexstr]
:local chk1 ""
:local chk2 ""
:local chrstr ""
:local lowerarray {"a"="A";"b"="B";"c"="C";"d"="D";"e"="E";"f"="F"}
:for x from=0 to=($hexlen - 2) step=2 do={
:s…
hex2chr hexadecimal to char
search tag # rextended hex2chr hexadecimal to char
Mmm… but simply:
[rextended@MATRIX] > :global hex2chr do={:return [[:parse "(\"\\$1\")"]]}
[rextended@MATRIX] > :put [$hex2chr 64]
d
[rextended@MATRIX] >
just do not pass lowercase or invalid hex digit, only uppercase.
see here for the function to convert a string of HEX value to a string of Chars, it also check lower/upper/invalid hex:
https://forum.mikrotik.com/viewtopic.php?f=9&t=129693&p=871742#p871742
definitive ip or ip-prefix posix regex
search tag # rextended definitive ip posix regex
remember than this are wroten for be put directly on script,
if tested on terminal you must add \ before the ?
if tested on regex101 must be removed \ before . and /
The used regexp
[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
match from 0.0.0.0 to 999.999.999.999
My POSIX regex is better, also match subnet mask, if present:
([0-2]{0,1}[0-9]{1,2}\\.){3}[0-2]{0,1}[0-9]{1,2}(\\/[0-3]{0,1}[0-9]{1,1}){0,1}
0.0.0.0 to 299.299.299.299
000…
auto add (starlink) classless route
search tag # rextended starlink classless route
Summary of the progress made so far:
By this setup on MikroTik DHCP Server I can simulate exactly what DHCP Server on Starlink device option 121 Classless-Route send to MikroTik DHCP Client:
/ip dhcp-server option
add code=121 name=Classless-Route value=0x20C0A8640100000000202278FFF40000000000647FFF05
/ip dhcp-server network
add ... dhcp-option=Classless-Route ...
Equivalent to:
Classless-Route = 192.168.100.1/32->0.0.0.0,34.120.255.244/32->0.…
int2hex num2hex integer number to hexadecimal convert function
search tag # rextended int2hex num2hex integer number hexadecimal convert function
Function to convert integer to hex (only positive numbers)
:global num2hex do={
:local number [:tonum $1]
:local hexadec "0"
:local remainder 0
:local hexChars "0123456789ABCDEF"
:if ($number > 0) do={:set hexadec ""}
:while ( $number > 0 ) do={
:set remainder ($number % 16)
:set number (($number-$remainder) / 16)
:set hexadec ([:pick $hexChars $remainder].$hexadec)
}
:i…
check host status
search tag # rextended check host status
evidenced errors on your script:
:global vdsdown
:local host 192.168.1.252 # better put the editable things up:local checkvds [/ping $host count=3]
:if ($checkvds = 0) do={ # $ must used for call variables:if ($vdsdown != true) do={
/log warning "Host $host is offline"; # useless ";" :set $vdsdown true # $ must not be used on set}
} else={
:if ($vdsdown != false = true) do={ # better != false instead of =true/log info "Host $host is online"; # usel…
dual wan A-B-C failover
search tag # rextended dual wan failover
It’s like you ask for dual WAN failover than a load balancing
Use this as example, you must disable default roure creation on dhcp clients and remove predefined routes on /ip route
:global isp1gateway 177.142.96.44
:global isp2gateway 192.168.0.254
/ip dns
set servers=1.1.1.1,8.8.8.8
/ip route
add comment="A - 1.1.1.1 must be reachable only from ISP1" distance=1 dst-address=1.1.1.1/32 gateway=$isp1gateway scope=10
add comment="B - Recursive Routi…
dual dhcp wan failover
search tag # rextended dual dhcp wan failover
This works only on 6.46.8+ and not in v7+
REMEMBER TO REMOVE “ADD DEFAULT ROUTE” ON DHCP CLIENTs
and add those scripts on “script” section of DHCP client
script for DHCP Client 1 = MAIN
/ip route
set [find where comment~"ISP1"] gateway=$"gateway-address"
script for DHCP Client 2 = FAILOVER
/ip route
set [find where comment~"ISP2"] gateway=$"gateway-address"
This must be pasted on new terminal, better if before do that remove all non dynamic r…
How to really block invalid ICMP, TCP, UDP packets and others (ver. 2021)
https://forum.mikrotik.com/viewtopic.php?f=9&t=83387&p=867386
comma separated value of interface list
search tag # rextended comma separated ethernet list
Shorter and clearer:
{
/interface ethernet
:local InterfaceList ""
:local separator ""
:foreach i,Interface in=[ find where default-name~"(combo|ether|sfp)*" ] do={
:set InterfaceList "$InterfaceList$separator$[ get $Interface name ]"
:if ($i = 0) do={ :set separator "," }
}
:log info $InterfaceList
}
And thanks for the hint to use “i”, I never stop discovery new things, thanks to all…
num2month mon2MON mon2num number month
thanks sir. i forgot to insert the pick date
:local Date [/system clock get date]
:global num2month do={ :return [:pick “REXJANFEBMARAPRMAYJUNJULAGOSEPOCTNOVDEC” [:pick $Date 0 3]+1)] ($13) (($13)+3)] }
:log info [$num2month]
today is JUN but i need to get the JUL
short address list ip address aggregator (to do)
search tag # rextended short address list ip address aggregator
Thanks for this share!!!
send whatsapp notification
if used in terminal ? should be replaced by ? otherwise MTiK would remove ?
asynchronous script execution
search tag # rextended execute
Bravo!
:global pingResult -1
{
:local jobID [:execute ":set pingResult [:ping count=5 1.1.1.1]"]
:while ([:len [/system script job find where .id=$jobID]] > 0) do={
:delay 1s
}
}
:put $pingResult
enable x64 mode on RouterOS x86 installed on x64 (virtual or not) machine
search tag # install routeros x86_64 ENABLE_X86_64
For enable 64 bit on RouterOS x86 installation
(obviously installed on 64 bit hardware with more than 4GB of ram)
“simply”
remove hard disk and connect it on another linux PC
OR
use a bootable USB with linux (ubuntu setup for example) for access on ext3 internal storage
and on folder /system/rw
“simply” create empty file named
ENABLE_X86_64
warning: all uppercase, with _ and NO SPACES (with right -rw-r–r–)
put back the hard disk,
sta…
random number generator (without OTP frills)
search tag # rextended random number generator
Random number between 0 and 99
:global randomnum do={
/system resource irq
:local tmpsum 0
:foreach i in=[find] do={:set tmpsum ($tmpsum + [get $i count])}
:set tmpsum [:tostr $tmpsum]
:local lentmp [:len $tmpsum]
:return [:tonum [:pick $tmpsum ($lentmp - 2) $lentmp]]
}
Random string between 00 and 99
:global randomstr do={
/system resource irq
:local tmpsum 0
:foreach i in=[find] do={:set tmpsum ($tmpsum …
default firewall rules
search tag # rextended default firewall rules
WARNING: default WAN and LAN interface list must be defined
WARNING: if you do not know what you are doing, you probably lose control of your device
The difference between v6.49.18 and 7.18 are on RED
MikroTik RouterOS 6.49.18 default firewall rules
for IPv4 must be also created interface lists, remember to correct assign interfaces inside lists and bridge.
/interface list
add name=WAN comment=defconf
add name=LAN comment=defconf
/interface li…
convert string to ip-prefix
search tag # rextended convert to ip prefix
Reordered and corrected some aspects…
/ip firewall address-list
{
:log info "Remove old bogon list"
remove [find where list="bogons"]
:log info "Fetching bogon list"
:local content ([/tool fetch url="https://www.team-cymru.org/Services/Bogons/fullbogons-ipv4.txt" mode=https output=user as-value]->"data")
:local contentLen [:len $content]
:local lineEnd -1
:local line ""
:local lastEnd -1
:log info "Adding bogons from memory"
:do { :set li…
dynamic variables
search tag # rextended dynamic variables
This:
:global $wan1 1;
:put ("wanSta" . $wan1);
:set ("wanStatus" . $wanIndex) 10
give two errors:
first one because the $ on front of wan1 is forbiden when declaring a global or local variable (I use 6.47.10)
second because the wan1 is undefined on second line for the reason writed before
third on last line you use another name wanStatus
The correct syntax is:
:global wan1 1
:put "wanSta$wan1"
:set wanSta1 10
but obviously do not create or s…
manage fetch errors
search tag # rextended manage fetch errors
I write one post a time, leave me the time!!!
Is not for suspance, I need some time to write and test…
This is the code:
/file remove [find where name="testfetch.txt"]
{
:local jobid [:execute file=testfetch.txt script="/tool fetch url=http://mikrotik.com"]
:put "Waiting the end of process for file testfetch.txt to be ready, max 20 seconds..."
:global Gltesec 0
:while (([:len [/sys script job find whe…
sort array, sort file by date, date2ymd
Hi
It is possible to get sorted array (by name or creation-time) with /file find ?
I need to delete recent n files
[Снимок экрана 2021-09-14 162542.png]
[admin@MikroTik7-Test] > /file print detail where name~"MikroTik7-Test_.+\\.backup\$"
0 name="MikroTik7-Test_2021-09-14_132825.backup" type="backup" size=72.9KiB creation-time=sep/14/2021 13:28:25
1 name="MikroTik7-Test_2021-09-14_132104.backup" type="backup" size=72.8KiB creation-time=sep/14/2021 13:21:04
15 name="MikroTik7-Test_2021-0…