Some Mikrotik Script Trics that can make your boring work easy
>>Change Multiple pppoe profile at once:
{
/ppp secret
:foreach id in=[find where profile="Profile-A"] do={
set $id profile="Profile-B"
}
}
if the profile shows unknown then use the profile name = "*8"
>>Move Multiple vlan to nother interface:
foreach i in=[/interface vlan find where interface=ether2] do={interface vlan set interface=ether3 $i}
>>Create Multiple vlan in a interface:
:for i from 1 to 50 do={/ int vlan add name=("vlan" . $i) vlan-id=$i interface=ether1}
>>Creating multiple queue in mikrotik at once:
:for x from 1 to 254 do={/queue simple add name="queue-$x" max-limit=2M/2M target="192.168.1.$x"}
>>Creating multiple PPPOE user at once:
:for i from 1 to 50 do={/ppp secret add name=("user" . $i) password=("pass" . $i) service=pppoe profile=1MB}
>>> Mikrotik firewall filter rule moving to the desired sequence number
ip firewall filter move [ /ip firewall filter find src-address-list="80_Mbps" ] "3"
>>Mikrotik Login LOG to Telegram
:local DeviceName [/system identity get name];
:local Time [/system clock get time];
:local Date [/system clock get date];
:local TelegramMessageText;
:global ParseLogAccountEndArrayID;
:local IDsEventsAccount [/log find where topics ~ "account"];
:local LenArrayIDs [:len $IDsEventsAccount];
:local StartArrayID [:find $IDsEventsAccount $ParseLogAccountEndArrayID];
:local EndArrayID ($IDsEventsAccount -> ($LenArrayIDs-1));
:if ($EndArrayID != $ParseLogAccountEndArrayID and [:tobool $ParseLogAccountEndArrayID] ) do={
:local StartArray [:find $IDsEventsAccount $ParseLogAccountLastRunID];
:for KeyArray from=($StartArrayID+1) to=($LenArrayIDs-1) do={
:local IDMessage ($IDsEventsAccount ->$KeyArray );
:set TelegramMessageText "$TelegramMessageText %0D%0A $[/log get number=$IDMessage time] - $[/log get number=$IDMessage message];";
}
# START SEND TELEGRAM MESSAGE
:local BotToken "6120514855:AAFIkwye7DKQ0w92O5bkT2YkR-r3vMnHcCk";
:local ChatID "-905535349";
:local ParseMode "html";
:local DisableWebPagePreview True;
:local SendText "\F0\9F\94\93 <b>$DeviceName: AUTH</b> $TelegramMessageText";
:local tgUrl "https://api.telegram.org/bot$BotToken/sendMessage?chat_id=$ChatID&text=$SendText&parse_mode=$ParseMode&disable_web_page_preview=$DisableWebPagePreview";
/tool fetch http-method=get url=$tgUrl keep-result=no;
# END SEND TELEGRAM MESSAGE
}
:set ParseLogAccountEndArrayID $EndArrayID;
>>Doube NAT Restrict
/ip firewall filter
add action=add-src-to-address-list address-list=double_router \
address-list-timeout=15m chain=forward connection-state=established \
in-interface=all-ppp src-address=10.70.0.0/16 ttl=less-than:62
/ip firewall filter
add action=drop chain=forward connection-state=new src-address-list=\
double_router ttl=less-than:62
>>Mikrotik Backup send to EMAIl:
>>OR
:local email "shaharul884@gmail.com"
:local rscfn "backup"
:local bakfn "bin"
/system
:local date [clock get date]
:local time [clock get time]
:local info [identity get name]
:local board ([resource get board-name])
:local files "$rscfn.rsc,$bakfn.backup"
:local Version [resource get version]
/system
:local serial "undefined"
:if (!($board~"(x86|CHR)")) do={
:global testrbsn "NO RouterBOARD"
:execute ":global testrbsn; :set testrbsn [/system routerboard get serial-number]"
:delay 1s
:set serial $testrbsn
:set testrbsn
} else={
:if ($board="x86") do={:set serial [license get software-id]}
:if ($board="CHR") do={:set serial [license get system-id]}
}
:if ($Version~"^7") do={
[:parse "/export show-sensitive file=$rscfn.rsc"]
} else={
/export file="$rscfn.rsc"
}
:delay 2s
/system backup save name="$bakfn"
:delay 2s
/tool e-mail send to="$email" subject="Mikrotik: Backup $info $Version $serial" file="$files" body="Automatic Backup of $info $serial at $date $time"
:delay 20s
:execute "/file remove $files"
:log info "Backup router=$info serial=$serial ok"