├── Array2Json.txt ├── Array2Str.txt ├── Call.txt ├── CharReplace.txt ├── Date.txt ├── Date2Sec.txt ├── File.txt ├── Loginpage.rsc ├── README.md ├── Replace.txt ├── Replace_simple.txt ├── Sec2Date.txt ├── Split.txt ├── TEST.txt ├── TEST2.txt ├── Time2Num.txt ├── ToLower.txt ├── ToUpper.txt ├── join.txt ├── map.txt └── random_login_blocker.rsc /Array2Json.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #Convert Array Value To json 3 | :global Json do={ 4 | :local i [:len $1];:local j 0; 5 | :local q "\"";:local a false; 6 | :foreach n,v in=$1 do={:set $j ($j+1); 7 | :if ([:typeof $n]!="num") do={:set $s ($s.$q.$n.$q.":");:set $a true;} 8 | :if ([:typeof $v]="num") do={:if ($i=$j) do={:set $s ($s.$v);} else={:set $s ($s.$v.",");}} else={ 9 | :if ([:typeof $v]!="array") do={:if ($i=$j) do={:set $s ($s.$q.$v.$q)} else={:set $s ($s.$q.$v.$q.",");}} else={ 10 | :if ($i=$j) do={:set $s ($s.[$Json $v])} else={:set $s ($s.[$Json $v].",");} 11 | }}} 12 | :if ($a) do={:return ("{".$s."}");} 13 | :return ("[".$s."]"); 14 | } -------------------------------------------------------------------------------- /Array2Str.txt: -------------------------------------------------------------------------------- 1 | :global Array2Str do={ 2 | :global Array2Str; 3 | :if ([:typeof $1]="str") do={:return ("\"$1\"");} 4 | :if ([:len $1]=0) do={:return ("\"\"");} 5 | :local str ""; 6 | :local a false; 7 | :foreach n,v in=$1 do={ 8 | :set $a ""; 9 | :if ([:typeof $n]!="num") do={:set $str ($str."{"."\"".$n."\""."=");:set $a ("}");} 10 | :if ([:typeof $v]="array") do={ 11 | :set $str ($str.[$Array2Str $v ].$a.","); 12 | } else={ 13 | :if ([:typeof $v]="str") do={ 14 | :set $str ($str."\"".$v."\"".$a.","); 15 | } else={ 16 | :set $str ($str.$v.$a.","); 17 | } 18 | } 19 | } 20 | :return ("(".[:pick $str 0 ([:len $str ]-1)].")"); 21 | } 22 | -------------------------------------------------------------------------------- /Call.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | #Call global Varable without define 3 | #------------------------------------------------------------------------------ 4 | :global test1 ("test1",4123,10.0.0.1); 5 | :global test2 34234; 6 | :global test3 do={:return ($1+$2);}; 7 | #Call global Varable without define 8 | :local code do={ 9 | :local get do={:local a [:parse ":global \"$1\";:return \$\"$1\";"];:return [$a];} 10 | :local t1 [$get "test1"]; 11 | :put $t1; 12 | :local t2 [$get "test2"]; 13 | :put $t2; 14 | #Call global Code without define ":global test3;" in code 15 | :local t3 [$get "test3"]; 16 | :put [$t3 2 4]; 17 | :put [$t3 10 5]; 18 | };[$code] 19 | #or 20 | { 21 | :local F do={:local a [:parse ":global \"$1\";:return \$\"$1\";"];:local b [$a];:return [$b $1 $2 $3];} 22 | :put [$F "my_global_Function_name" "v1" "v2" "v3"]; 23 | } 24 | #------------------------------------------------------------------------------ 25 | #Call Code From File With Cache; 26 | #------------------------------------------------------------------------------ 27 | #save any code in file mycode.txt; 28 | #example save this :put "hellow";:return ($1+$2*$3); 29 | :global Func do={ 30 | :global F; 31 | :do {:if (!any($F->"$f")) do={:if ([:len $F]=0) do={:set $F [:toarray ""];};:set ($F->"$f") [:parse [/file get "$f" contents]];}} on-error={:log error "error when call Func not found file=$f";:error "not found $f";} 32 | :local a ($F->"$f"); 33 | :return [$a $1 $2 $3]; 34 | } 35 | #:put [$Func f="Function file name" v1 v2 v3]; 36 | #first time only the script will get code from files and execute it 37 | :put [$Func f="mycode.txt" 1 4 5]; 38 | #then it will get code from memory "global F" 39 | :put [$Func f="mycode.txt" 9 7 10]; 40 | #------------------------------------------------------------------------------ 41 | -------------------------------------------------------------------------------- /CharReplace.txt: -------------------------------------------------------------------------------- 1 | :global CharReplace do={ 2 | :if ([:len $2]=0) do={:return $1;} 3 | :local c ""; 4 | :for i from=0 to=([:len $1]-1) do={ 5 | :if ([:len [:find $2 [:pick $1 $i]]]!=0) do={ 6 | :set $c ($c.[:pick $3 [:find $2 [:pick $1 $i]]]); 7 | } else={ 8 | :set $c ($c.[:pick $1 $i]); 9 | } 10 | } 11 | :return ($c); 12 | } -------------------------------------------------------------------------------- /Date.txt: -------------------------------------------------------------------------------- 1 | :global Date do={ 2 | :if (any$2) do={:set $2 ":";} 3 | :return ([:pick $1 7 11]."$2".[:pick [("01","02","03","04","05","06","07","08","09","10","11","12")] [:find [("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")] [:pick $1 0 3]]]."$2".[:pick $1 4 6]); 4 | } -------------------------------------------------------------------------------- /Date2Sec.txt: -------------------------------------------------------------------------------- 1 | :global Date2Sec do={ 2 | :local y [:pick $1 7 11]; 3 | :local m [:pick $1 0 3]; 4 | :local d [:pick $1 4 6]; 5 | :local h [:pick $2 0 2]; 6 | :local n [:pick $2 3 5]; 7 | :local s [:pick $2 6 8]; 8 | :local k 1; 9 | :if (($y%4)>0) do={:set $k 0;} 10 | :local mn [:find ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec") $m]; 11 | :local ds [:pick (0,31,(59+$k),(90+$k),(120+$k),(151+$k),(181+$k),(212+$k),(243+$k),(273+$k),(304+$k),(334+$k)) $mn ]; 12 | :return (($y*365*24*60*60)+(($ds+$d)*86400)+($h*3600)+($n*60)+$s+($y*3600*6)); 13 | } -------------------------------------------------------------------------------- /File.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | #Creat any directory name and any file extension 3 | #------------------------------------------------------------------------------ 4 | #example create new path "folder1/folder2/folder3/osama.html"; 5 | :global File do={ 6 | :local S do={:local o;:local L [:len $2];:local j 0;:local i (0-$L);:if ($L=0) do={:return $1;};:while ([:set $i [:find $1 $2 ($i+$L-1)];(any$i)]) do={:set $o ($o,([:pick $1 $j $i]));:set $j ($i+$L);};:return ($o,([:pick $1 $j [:len $1]]));} 7 | :local a [$S $1 "/"]; 8 | :local n [:pick $a ([:len $a ]-1)]; 9 | :local d ""; 10 | :local x ""; 11 | /ip smb shares remove [find where comment="temp"]; 12 | /ip smb shares {:foreach i,f in=[:pick $a 0 ([:len $a ]-1)] do={:set $d ($d."/".$f);[add name="$d" directory=$d comment="temp"];:delay 10ms;}} 13 | :set $d [:pick $d 1 [:len $d]]; 14 | :delay 10ms; 15 | /tool sniffer {:set $x [get file-name];[set file-name=($d."/".$n)];[quick duration=00:00:00.001 ip-address=3.3.3.3 ];[set file-name=$x]} 16 | /ip smb shares remove [find where comment="temp"]; 17 | } 18 | $File "folder1/folder2/folder3/osama.html" 19 | #------------------------------------------------------------------------------ 20 | -------------------------------------------------------------------------------- /Loginpage.rsc: -------------------------------------------------------------------------------- 1 | /ip firewall filter 2 | add action=add-src-to-address-list address-list=BEFORELOGIN disabled=yes address-list-timeout=5s chain=input dst-port=64873 hotspot=from-client,!auth protocol=tcp comment="EngOsama" place-before=0; 3 | add action=add-src-to-address-list address-list=ONLOGIN disabled=yes address-list-timeout=10s chain=input dst-port=64873 hotspot=from-client,auth protocol=tcp comment="EngOsama" src-address-list=BEFORELOGIN place-before=0; 4 | add action=drop chain=forward hotspot=from-client,auth disabled=yes port=80,443,53 protocol=tcp src-address-list=ONLOGIN comment="EngOsamah" place-before=0; 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mikrotik 2 | useful mikrotik functions 3 | 4 | ----------------------------------------------------------------------------------------------------------------- 5 | 1-Repalce 6 | ----------------------------------------------------------------------------------------------------------------- 7 | #Replace Function [$Replace "string" "string1" "string2" number]; 8 | 9 | #Replace Function [$Replace "string" "string1" "string2" number]; output is string 10 | 11 | #Or [$Replace "string" ("str1","str2","str3") "re_str" number]; output is string 12 | 13 | #Or [$Replace "string" ("str1","str2","str3") ("re_str1","re_str2","re_str3") number]; output is string 14 | 15 | #Or [$Replace (array) ("str1","str2","str3") ("re_str1","re_str2","re_str3") number]; output is array 16 | 17 | #Test The Function 18 | 19 | #:put [$Replace "osama test ali" "a" "A" ]; 20 | 21 | #:put [$Replace "osama test ali" "ama" "AMA" ]; 22 | 23 | #:put [$Replace "osama test ali" ("ama","te") ("AMA","TE") ]; 24 | 25 | #:put [$Replace ("osama","test","ali") "test" "TEST" ]; 26 | 27 | #:put [$Replace ("osama","test","test2","ali") ("test","ali") ("TEST3","ALI") ]; 28 | 29 | #------------------------------------------------------------------------------------------ 30 | 31 | #array to string Function 32 | 33 | #------------------------------------------------------------------------------------------ 34 | { 35 | 36 | #array value 37 | 38 | :local arr ("test",43242,10.4.4.1,{"test1"=321},{"test2"=("v1","v2")},{"test3"=({"v1"=100},{"v2"=99})}); 39 | 40 | #convert array to string 41 | 42 | :local str [$Array2Str $arr]; 43 | 44 | #show string 45 | 46 | :put $str; 47 | 48 | #return string to array 49 | 50 | :local a [parse $str]; 51 | 52 | #show array 53 | 54 | :put [$a]; 55 | 56 | #get value test3 -> v1 57 | 58 | :put ([$a]->"test3"->"v1"); 59 | 60 | } 61 | 62 | #------------------------------------------------------------------------------------------ 63 | 64 | #split , map and join functions 65 | 66 | #------------------------------------------------------------------------------------------ 67 | 68 | { 69 | 70 | #string 71 | 72 | :local str "osama"; 73 | 74 | #Split String 75 | 76 | :local arr [$Split $str ]; 77 | 78 | :put $arr; 79 | 80 | #function in map 81 | 82 | :local function do={:return "($n=$v)";} 83 | 84 | :local arr2 [$map $arr $function ]; 85 | 86 | #Split array after map 87 | 88 | :put $arr2; 89 | 90 | #Join the array by "," and convert to string 91 | 92 | :local str2 [$Join $arr2 ","]; 93 | 94 | #show the output string 95 | 96 | :put $str2; 97 | 98 | } 99 | 100 | #------------------------------------------------------------------------------------------ 101 | 102 | #--------------------------------------------------------------- 103 | 104 | #Convert Date and time ex="jan/23/2020" 22:44:21 To Seconds then return to date and time 105 | 106 | #--------------------------------------------------------------- 107 | 108 | :local date [/system clock get date ]; 109 | 110 | :local time [/system clock get time ]; 111 | 112 | :local seconds [$Date2Sec $date $time]; 113 | 114 | #show seconds 115 | 116 | :put $seconds; 117 | 118 | #return secounds to date and time 119 | 120 | :local das [$Sec2Date $seconds]; 121 | 122 | :local date2 [:pick $das 0]; 123 | 124 | :local time2 [:pick $das 1]; 125 | 126 | #show date 127 | 128 | :put $date2; 129 | 130 | #show time 131 | 132 | :put $time2; 133 | 134 | #--------------------------------------------------------------------------------------------------------------------------------------- 135 | 136 | ----------------------------------------- 137 | -------------------------------------------------------------------------------- /Replace.txt: -------------------------------------------------------------------------------- 1 | :global Replace do={ 2 | :local v1 $1; 3 | :local v2 [:toarray $2]; 4 | :local v3 [:toarray $3]; 5 | :local v4 [:tonum $4]; 6 | :local len1 [:len $v1]; 7 | :local len2 [:len $v2]; 8 | :local len3 [:len $v3]; 9 | :local v2r $v2; 10 | :local v3r $v3; 11 | :local neer -1; 12 | :local last -1; 13 | :local where -1; 14 | :local output; 15 | :local t [:typeof $v1]; 16 | :local n 0; 17 | :if ([:len $v4]=0) do={:set $v4 $len1;} 18 | :while ($n<=$v4) do={ 19 | :set $neer $len1; 20 | :foreach v in=$v2 do={ 21 | :set $where [:find $v1 $v ($last-1)]; 22 | :if ([:len $where]>0) do={ 23 | :if ($where<$neer) do={ 24 | :set $neer $where; 25 | :set $v2r $v; 26 | } 27 | } 28 | } 29 | :if ($len3>1) do={ 30 | :set $v3r [:pick $v3 [:find $v2 $v2r]]; 31 | } 32 | :if ($t="array") do={ 33 | :if (($neer>=$len1)||($n=$v4)) do={:return ($output,[:pick $v1 $last $len1]);} 34 | :set $output ($output,[:pick $v1 $last $neer],$v3r); 35 | :set $last ($neer+1); 36 | } else={ 37 | :if (($neer>=$len1)||($n=$v4)) do={:return ($output.[:pick $v1 $last $len1]);} 38 | :set $output ($output.[:pick $v1 $last $neer].$v3r); 39 | :set $last ($neer+[:len $v2r]); 40 | } 41 | :set $n ($n+1); 42 | } 43 | :return $output; 44 | } 45 | -------------------------------------------------------------------------------- /Replace_simple.txt: -------------------------------------------------------------------------------- 1 | :global Replace do={ 2 | :local o; 3 | :local L [:len $2]; 4 | :local j 0; 5 | :local i (0-$L); 6 | :local n 0; 7 | :if ($L=0) do={:set $n 1;} 8 | :while ([:set $i [:find $1 $2 ($i+$L-1+$n)];(any$i)]) do={ 9 | :set $o ($o.([:pick $1 $j $i]).$3); 10 | :set $j ($i+$L); 11 | :if ([:len $o]=$4) do={:return ($o.([:pick $1 $j [:len $1]]));} 12 | } 13 | :return ($o.([:pick $1 $j [:len $1]])); 14 | } -------------------------------------------------------------------------------- /Sec2Date.txt: -------------------------------------------------------------------------------- 1 | :global Sec2Date do={ 2 | :local y ($1/(31557600)); 3 | :local d (($1%(31557600))/86400); 4 | :local time [:totime ($1%(86400))]; 5 | :local k 1; 6 | :if (($y%4)>0) do={:set $k 0;}; 7 | :if ($d=0) do={:return ("dec/31/$($y-1)",$time);}; 8 | :local mn [:find ((($d>=1)and($d<=31)),(($d>31)and($d<=(59+$k))),(($d>(59+$k))and($d<=(90+$k))),(($d>(90+$k))and($d<=(120+$k))),(($d>(120+$k))and($d<=(151+$k))),(($d>(151+$k))and($d<=(181+$k))),(($d>(181+$k))and($d<=(212+$k))),(($d>(212+$k))and($d<=(243+$k))),(($d>(243+$k))and($d<=(273+$k))),(($d>(273+$k))and($d<=(304+$k))),(($d>(304+$k))and($d<=(334+$k))),(($d>(334+$k))and($d<=(365+$k)))) true]; 9 | :local mo [:pick ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec","dec") $mn ]; 10 | :local da ($d-([:pick (0,31,(59+$k),(90+$k),(120+$k),(151+$k),(181+$k),(212+$k),(243+$k),(273+$k),(304+$k),(334+$k)) $mn])); 11 | :if ($da<10) do={:return (($mo."/".0.$da."/".$y),$time);} 12 | :return (($mo."/".$da."/".$y),$time); 13 | } -------------------------------------------------------------------------------- /Split.txt: -------------------------------------------------------------------------------- 1 | :global Split do={ 2 | :local o; 3 | :local L [:len $2]; 4 | :local j 0; 5 | :local i (0-$L); 6 | :local n 0; 7 | :if ($L=0) do={:set $n 1;} 8 | :while ([:set $i [:find $1 $2 ($i+$L-1+$n)];(any$i)]) do={ 9 | :set $o ($o,([:pick $1 $j $i])); 10 | :set $j ($i+$L); 11 | :if ([:len $o]=$3) do={:return ($o,([:pick $1 $j [:len $1]]));} 12 | } 13 | :return ($o,([:pick $1 $j [:len $1]])); 14 | } -------------------------------------------------------------------------------- /TEST.txt: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------ 2 | #array to string Function 3 | #------------------------------------------------------------------------------------------ 4 | { 5 | #array value 6 | :local arr ("test",43242,10.4.4.1,{"test1"=321},{"test2"=("v1","v2")},{"test3"=({"v1"=100},{"v2"=99})}); 7 | #convert array to string 8 | :local str [$Array2Str $arr]; 9 | #show string 10 | :put $str; 11 | #return string to array 12 | :local a [parse $str]; 13 | #show array 14 | :put [$a]; 15 | #get value test3 -> v1 16 | :put ([$a]->"test3"->"v1"); 17 | } 18 | #------------------------------------------------------------------------------------------ 19 | #split , map and join functions 20 | #------------------------------------------------------------------------------------------ 21 | { 22 | #string 23 | :local str "osama"; 24 | #Split String 25 | :local arr [$Split $str ]; 26 | :put $arr; 27 | #function in map 28 | :local function do={:return "($n=$v)";} 29 | :local arr2 [$map $arr $function ]; 30 | #Split array after map 31 | :put $arr2; 32 | #Join the array by "," and convert to string 33 | :local str2 [$Join $arr2 ","]; 34 | #show the output string 35 | :put $str2; 36 | } 37 | #------------------------------------------------------------------------------------------ 38 | -------------------------------------------------------------------------------- /TEST2.txt: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------- 2 | #Convert Date and time ex="jan/23/2020" 22:44:21 To Seconds then return to date and time 3 | #--------------------------------------------------------------- 4 | :local date [/system clock get date ]; 5 | :local time [/system clock get time ]; 6 | :local seconds [$Date2Sec $date $time]; 7 | #show seconds 8 | :put $seconds; 9 | #return secounds to date and time 10 | :local das [$Sec2Date $seconds]; 11 | :local date2 [:pick $das 0]; 12 | :local time2 [:pick $das 1]; 13 | #show date 14 | :put $date2; 15 | #show time 16 | :put $time2; 17 | #--------------------------------------------------------------- 18 | -------------------------------------------------------------------------------- /Time2Num.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #Convert Time ex="3w1d10:10:32" To Seconds 3 | :global Time2Num do={ 4 | :local T [:totime $1 ]; 5 | :local W 0; 6 | :local D 0; 7 | :local S 1; 8 | :local A 0; 9 | :if ([:pick $T 0]="-") do={:set $A 1;:set S (0-1) ;} 10 | :if ($T~"w") do={:set $W [:pick $T $A [:find $T "w"]]} 11 | :if ($T~"d") do={:set $D [:pick $T ([:find $T "d"]-1)]} 12 | :local m [:find $T ":"]; 13 | :local ta [:pick $T ($m-2) ($m+6)]; 14 | :return ((($W*7+$D)*24*60*60+[:tonum [:pick $ta 0 2]]*60*60+[:tonum [:pick $ta 3 5]]*60+[:tonum [:pick $ta 6 8]])*$S) 15 | } -------------------------------------------------------------------------------- /ToLower.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #Convert string to LowCase 3 | #:put [$LowCase "OSAma" ]; 4 | :global LowCase do={ 5 | :local C ("\41","\42","\43","\44","\45","\46","\47","\48","\49","\4A","\4B","\4C","\4D","\4E","\4F","\50","\51","\52","\53","\54","\55","\56","\57","\58","\59","\5A","\61","\62","\63","\64","\65","\66","\67","\68","\69","\6A","\6B","\6C","\6D","\6E","\6F","\70","\71","\72","\73","\74","\75","\76","\77","\78","\79","\7A"); 6 | :local L ("\61","\62","\63","\64","\65","\66","\67","\68","\69","\6A","\6B","\6C","\6D","\6E","\6F","\70","\71","\72","\73","\74","\75","\76","\77","\78","\79","\7A","\61","\62","\63","\64","\65","\66","\67","\68","\69","\6A","\6B","\6C","\6D","\6E","\6F","\70","\71","\72","\73","\74","\75","\76","\77","\78","\79","\7A"); 7 | :local o ""; 8 | :for i from=0 to=([:len $1]-1) do={:if ([:len [:find $C [:pick $1 $i]]]!=0) do={:set $o ($o.[:pick $L [:find $C [:pick $1 $i]]]);} else={:set $o ($o.[:pick $1 $i]);}} 9 | :return $o; 10 | } 11 | -------------------------------------------------------------------------------- /ToUpper.txt: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #Convert string to UpCase [$UpCase "string" ]; 3 | #:put [$UpCase "OSAma" ]; 4 | :global UpCase do={ 5 | :local C ("\41","\42","\43","\44","\45","\46","\47","\48","\49","\4A","\4B","\4C","\4D","\4E","\4F","\50","\51","\52","\53","\54","\55","\56","\57","\58","\59","\5A","\61","\62","\63","\64","\65","\66","\67","\68","\69","\6A","\6B","\6C","\6D","\6E","\6F","\70","\71","\72","\73","\74","\75","\76","\77","\78","\79","\7A"); 6 | :local U ("\41","\42","\43","\44","\45","\46","\47","\48","\49","\4A","\4B","\4C","\4D","\4E","\4F","\50","\51","\52","\53","\54","\55","\56","\57","\58","\59","\5A","\41","\42","\43","\44","\45","\46","\47","\48","\49","\4A","\4B","\4C","\4D","\4E","\4F","\50","\51","\52","\53","\54","\55","\56","\57","\58","\59","\5A"); 7 | :local o ""; 8 | :for i from=0 to=([:len $1]-1) do={:if ([:len [:find $C [:pick $1 $i]]]!=0) do={:set $o ($o.[:pick $U [:find $C [:pick $1 $i]]]);} else={:set $o ($o.[:pick $1 $i]);}} 9 | :return $o; 10 | } -------------------------------------------------------------------------------- /join.txt: -------------------------------------------------------------------------------- 1 | :global Join do={ 2 | :local o; 3 | :foreach i in=$1 do={ 4 | :set $o ($o.$i.$2); 5 | } 6 | :return [:pick $o 0 ([:len $o ]-[:len $2])]; 7 | } -------------------------------------------------------------------------------- /map.txt: -------------------------------------------------------------------------------- 1 | :global map do={ 2 | :local o [:toarray ""]; 3 | :foreach n,v in=$1 do={ 4 | :set ($o->$n) [$2 n=$n v=$v]; 5 | } 6 | :return $o; 7 | } -------------------------------------------------------------------------------- /random_login_blocker.rsc: -------------------------------------------------------------------------------- 1 | 2 | #--------------------- 1 ------------------------- 3 | { 4 | /ip firewall raw 5 | add action=drop chain=prerouting hotspot=from-client,!auth src-address-list=BLOCKED; 6 | add action=jump chain=prerouting content="/login" dst-address-type=local dst-port=80,8080,3128,64870-64878,443 hotspot=from-client,!auth jump-target=TRY_LOGIN protocol=tcp src-address-list=!hotspot-login; 7 | add action=jump chain=TRY_LOGIN content="username=" jump-target=CHECK; 8 | add action=jump chain=TRY_LOGIN content="user=" jump-target=CHECK; 9 | add action=add-src-to-address-list address-list=BLOCKED address-list-timeout=5m chain=CHECK log=yes log-prefix="BLOCK LOGIN USER :" src-address-list=hotspot-login-10; 10 | :for i from=10 to=1 step=-1 do={add action=add-src-to-address-list address-list="hotspot-login-$i" address-list-timeout=2m chain=CHECK src-address-list=("hotspot-login-".($i-1));}; 11 | add action=add-src-to-address-list address-list=hotspot-login-0 address-list-timeout=1m chain=CHECK; 12 | add action=add-src-to-address-list address-list=hotspot-login src-address-list=!hotspot-login-10 address-list-timeout=1s chain=CHECK; 13 | add action=accept chain=CHECK; 14 | } 15 | 16 | 17 | #--------------------- 2 ------------------------- 18 | 19 | /ip firewall raw add action=drop chain=prerouting hotspot=from-client,!auth src-address-list=BLOCKED place-before=0; 20 | /system scheduler add start-date="Jan/01/2000" start-time="00:00:00" name="BLOCKER" interval=00:01:00 on-event="{\r\ 21 | \n:local Time [/system clock get time];\r\ 22 | \n:local IPS [:toarray \"\"];\r\ 23 | \n:foreach i in=[/log print as-value where topics=hotspot,info,debug && message~\"login failed\" && time>(\$Time-00:03:00) && time<(\$Time+00:03:00)] do={\ 24 | :local IP [:pick (\$i->\"message\") ([:find (\$i->\"message\") (\"(\")]+1) [:find (\$i->\"message\") (\")\")]];:set (\$IPS->\$IP) ((\$IPS->\$IP)+1);};\r\ 25 | \n:foreach i,n in=\$IPS do={:if (\$n>=20) do={/ip firewall address-list add address=\$i list=BLOCKED timeout=00:05:00;/log warning (\"BLOCK USER IP = \$i\");}}\r\ 26 | \n}\r\ 27 | \n" 28 | --------------------------------------------------------------------------------