mirror of
https://github.com/furaihan/simple-mikrotik-script.git
synced 2025-06-24 06:58:37 +02:00
Merge pull request #6 from furaihan/experiment
merge successful experiment
This commit is contained in:
commit
449299f4d4
4 changed files with 57 additions and 44 deletions
|
@ -1,27 +1,31 @@
|
|||
global cpuarray ([/system resource get value-name=cpu-load])
|
||||
local isInternetConnected
|
||||
local cpuarray
|
||||
local rebootIfHigh false
|
||||
local setup do={
|
||||
delay 950ms;
|
||||
global cpuarray
|
||||
set cpuarray ([/system resource get value-name=cpu-load],$cpuarray)
|
||||
}
|
||||
set cpuarray ([/system resource get value-name=cpu-load])
|
||||
#Change the value below to change the number of CPU load sample to average
|
||||
local cpusample 20
|
||||
for i from=1 to=[$cpusample -1] do={
|
||||
$setup
|
||||
delay 950ms;
|
||||
set cpuarray ([/system resource get value-name=cpu-load],$cpuarray)
|
||||
}
|
||||
put $cpuarray
|
||||
local totalcpuarray 0
|
||||
#calculating the average
|
||||
foreach value in=$cpuarray do={ set totalcpuarray ($totalcpuarray + $value)}
|
||||
:put $totalcpuarray
|
||||
local avgcpu ($totalcpuarray / [:len $cpuarray])
|
||||
if ($avgcpu > 65) do={
|
||||
global CheckConnection
|
||||
$CheckConnection
|
||||
global ConnectionAvailable
|
||||
:global ConnectionAvailable
|
||||
$ConnectionAvailable
|
||||
if ($ConnectionAvailable=true) do={
|
||||
global CHATID
|
||||
global BOTID
|
||||
local sendToTelegram ("Mikrotik ".[/system resource get value-name=board-name]."(".[/sy id get value-name=name].") :%0A\E2\9A\A0 \E2\9A\A0 <b>CPU Load Report</b>%0AAverage: $avgcpu%25%0ACPU Samples: $cpusample%0AReboot if CPU sample show highload: $rebootIfHigh")
|
||||
local maxcpu ($cpuarray->0)
|
||||
local mincpu ($cpuarray->0)
|
||||
foreach i in=$cpuarray do={
|
||||
if ($i > $maxcpu) do={ set maxcpu $i}
|
||||
if ($i < $mincpu) do={ set mincpu $i}
|
||||
}
|
||||
local sendToTelegram ("Mikrotik ".[/system resource get value-name=board-name]."(".[/sy id get value-name=name].") :%0A\E2\9A\A0 \E2\9A\A0 <b>CPU Load Report</b>%0AMax: $maxcpu%0AMin: $mincpu%0AAverage: $avgcpu%25%0ACPU Samples: $cpusample%0AReboot if CPU sample show highload: $rebootIfHigh")
|
||||
/tool fetch url="https://api.telegram.org/bot$BOTID/sendMessage\?chat_id=$CHATID&text=$sendToTelegram&parse_mode=html" keep-result=no;
|
||||
} else={
|
||||
log warning message="Cannot send message to telegram. is internet connected?"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
global CheckConnection
|
||||
$CheckConnection
|
||||
global ConnectionAvailable
|
||||
:global ConnectionAvailable
|
||||
$ConnectionAvailable
|
||||
if ($ConnectionAvailable=true) do={
|
||||
global CHATID
|
||||
global BOTID
|
||||
|
|
56
first-setup
56
first-setup
|
@ -3,54 +3,52 @@
|
|||
:global CHATID ("-4936xxx")
|
||||
#Change telegram bot id below with your own
|
||||
:global BOTID ("62xxxxxxxx:AAExxxx")
|
||||
:global GetMacVendor
|
||||
:set GetMacVendor do={
|
||||
local MacAddress [:tostr $1]
|
||||
:global GetMacVendor do={
|
||||
:do {
|
||||
local result ([/tool fetch mode=https http-method=get url=("https://api.macvendors.com/".[:pick [:tostr $MacAddress] 0 8 ]) as-value output=user ]->"data")
|
||||
return $result
|
||||
return ([/tool fetch mode=https http-method=get url=("https://api.macvendors.com/".[:pick [:tostr $1] 0 8 ]) as-value output=user ]->"data")
|
||||
} on-error={
|
||||
return "Error! this probably cause from unknown vendor or a connection problem"
|
||||
return "vendor not found"
|
||||
}
|
||||
}
|
||||
#source: https://s.id/q4f-O
|
||||
global ConvertLowerCase do={
|
||||
local alphabet {"A"="a";"B"="b";"C"="c";"D"="d";"E"="e";"F"="f";"G"="g";"H"="h";"I"="i";"J"="j";"K"="k";"L"="l";"M"="m";"N"="n";"O"="o";"P"="p";"Q"="q";"R"="r";"S"="s";"T"="t";"U"="u";"V"="v";"X"="x";"Z"="z";"Y"="y";"W"="w"};
|
||||
local result
|
||||
local character
|
||||
for strings from=0 to=([:len $1] - 1) do={
|
||||
local single [:pick $1 $strings]
|
||||
set character ($alphabet->$single)
|
||||
if ([:typeof $character] = "str") do={set single $character}
|
||||
:global ConvertLowerCase do={
|
||||
:local alphabet {"A"="a";"B"="b";"C"="c";"D"="d";"E"="e";"F"="f";"G"="g";"H"="h";"I"="i";"J"="j";"K"="k";"L"="l";"M"="m";"N"="n";"O"="o";"P"="p";"Q"="q";"R"="r";"S"="s";"T"="t";"U"="u";"V"="v";"X"="x";"Z"="z";"Y"="y";"W"="w"};
|
||||
:local result
|
||||
:local character
|
||||
:for strings from=0 to=([:len $1] - 1) do={
|
||||
:local single [:pick $1 $strings]
|
||||
:set character ($alphabet->$single)
|
||||
:if ([:typeof $character] = "str") do={set single $character}
|
||||
:set result ($result.$single)
|
||||
}
|
||||
:return $result
|
||||
}
|
||||
|
||||
global ConvertUpperCase do={
|
||||
local alphabet {"a"="A";"b"="B";"c"="C";"d"="D";"e"="E";"f"="F";"g"="G";"h"="H";"i"="I";"j"="J";"k"="K";"l"="L";"m"="M";"n"="N";"o"="O";"p"="P";"q"="Q";"r"="R";"s"="S";"t"="T";"u"="U";"v"="V";"x"="X";"z"="Z";"y"="Y";"w"="W"};
|
||||
local result
|
||||
local character
|
||||
for strings from=0 to=([:len $1] - 1) do={
|
||||
local single [:pick $1 $strings]
|
||||
set character ($alphabet->$single)
|
||||
if ([:typeof $character] = "str") do={set single $character}
|
||||
:global ConvertUpperCase do={
|
||||
:local alphabet {"a"="A";"b"="B";"c"="C";"d"="D";"e"="E";"f"="F";"g"="G";"h"="H";"i"="I";"j"="J";"k"="K";"l"="L";"m"="M";"n"="N";"o"="O";"p"="P";"q"="Q";"r"="R";"s"="S";"t"="T";"u"="U";"v"="V";"x"="X";"z"="Z";"y"="Y";"w"="W"};
|
||||
:local result
|
||||
:local character
|
||||
:for strings from=0 to=([:len $1] - 1) do={
|
||||
:local single [:pick $1 $strings]
|
||||
:set character ($alphabet->$single)
|
||||
:if ([:typeof $character] = "str") do={set single $character}
|
||||
:set result ($result.$single)
|
||||
}
|
||||
:return $result
|
||||
}
|
||||
global CheckConnection do={
|
||||
global ConnectionAvailable
|
||||
tool flood-ping 8.8.8.8 count=10 do={
|
||||
:global ConnectionAvailable do={
|
||||
:local internet
|
||||
/tool flood-ping 8.8.8.8 count=10 do={
|
||||
/if ($received > 8) do={
|
||||
set $ConnectionAvailable [tobool true]
|
||||
:set $internet true;
|
||||
} else={
|
||||
set $ConnectionAvailable [tobool false]
|
||||
:set internet false;
|
||||
}
|
||||
}
|
||||
:return $internet
|
||||
}
|
||||
#This script is inspired by TSOKOTSA's script published in the Mikrotik forum
|
||||
global GenerateRandomString do={
|
||||
:global GenerateRandomString do={
|
||||
:local hour [:pick [/system clock get time] 0 2]
|
||||
:local hourx
|
||||
:local minute [:pick [/system clock get time] 3 5]
|
||||
|
@ -86,7 +84,7 @@ global GenerateRandomString do={
|
|||
:set utsec ($utsec + 25)
|
||||
:set minute ($minute + 60)
|
||||
}
|
||||
:local string ("H","3","N","J","L","g","R","b","O","i","9","U","F","G","G","7","k","M","q","F","u","5","w","v","o","O","Q","V","r","6","9","l","u","n","Q","l","M","C","9","j","a","s","Y","h","K","S","N","T","d","H","i","f","E","f","q","0","7","0","w","s","X","h","9","b","X","b","n","n","R","E","z","q","r","w","7","Z","N","5","d","2","P","4","q","V","o","T","b","H","X","I","f","K","6","b","x","y","t","B","E","c","S","m","f","A","9","J","V","H","s","W","l","m","V","Z","p","u","c","r","1","Q","A","Z","2","h","E","P","t","M","c","K","V","B","g","z","J","x","k","y","q","W","K","p","i","R","Z","R","7","A","5","Y","a","A","o","H","X","4","6","9","R","Z","A","d","c","i","L","K","5","T","g","f","W","M","Y","S","J","v","V","t","N","O","F","T","v","6","y","u","p","0","H","W","Y","i","G","I","X","A","W","P","u","l","9","t","1","s","Q","a","e","I","N","E","5","K","O","l","E","m","3","L","P","2","4","s","O","y","Y","V","l","3","y","T","D","b","3","6","N","F","x","4","7","f","9","6","1","R","1","q","T","Z","3","U","W","M","X","H","z","o","T","V","e","O","G","m","0","Q","t","c","8","9","6","g","8","X","f","l","Y","V","a","t","O","5","e","z","C","2","S","K","6","e","Q","d","K","v","j","j")
|
||||
:local string ("fmIHMh52a2sSFIkSCxXkazAiBN09ypjm8F7fK0TxwTGXzaf054139uXhkEwF13Byi58JoA3lvfQr4Y6Ff257Nn5j06FI4eyzskfZybp9KjTnF9YATlBlTfP5j9uzTHspdnY6GfdQA4ekCl83qX2h382FlJv2iQFQPVZfFl15zBcqiV6TQlG3ytdQNyYJWEFy61305atf965w39iP4k6CCM5Ol0wdYZHFfcc0xFpr1ONybU9Dc3FtMCiDaGIzHu9BW4faZE2s938qs9j07pPiCfuD8OWqFEX9ukPkLl4kuNq3VjYJ1Av7W5n2")
|
||||
:local RandomString
|
||||
:set RandomString ([:pick $string ($second + uthour)].[:pick $string ($secondx + $uthour)].[:pick $string ($minute + $utsec - $hour)].[:pick $string ($minute + $uthour + $secondx)].[:pick $string [:tonum ($hundred + $uthour)]].[:pick $string [:tonum ($hundred2 + $utsec)]].[:pick $string [:tonum $hundred3]].[:pick $string ($utmin + $hourx + $second)].[:pick $string ($hourx + $hour + $second)].[:pick $string ($secondx + $utsec)])
|
||||
:return $RandomString
|
||||
|
|
12
quad9-doh.rsc
Normal file
12
quad9-doh.rsc
Normal file
|
@ -0,0 +1,12 @@
|
|||
/ip dns
|
||||
set allow-remote-requests=yes cache-max-ttl=2d cache-size=8192KiB \
|
||||
query-server-timeout=4s query-total-timeout=20s servers=\
|
||||
9.9.9.9,149.112.112.112,2620:fe::fe,2620:fe::fe:9 use-doh-server=\
|
||||
https://dns.quad9.net/dns-query
|
||||
/ip dns static
|
||||
add address=104.16.248.249 name=cloudflare-dns.com type=A
|
||||
add address=104.16.249.249 name=cloudflare-dns.com type=A
|
||||
/ip firewall nat
|
||||
add action=redirect chain=dstnat comment=DNS dst-port=53 protocol=udp \
|
||||
to-ports=53
|
||||
add action=redirect chain=dstnat dst-port=53 protocol=tcp to-ports=53
|
Loading…
Add table
Add a link
Reference in a new issue