Полезные скрипты для Mikrotik

Последние изменения: 27.06.2019
Отключить от wifi пользователей, неактивных более 20 минут:

:foreach i in=[/ip hotspot host find] do={
:local idletime [ /ip hotspot host get $i idle-time ]
:local mac [ /ip hotspot host get $i mac-address ]
:if ( $idletime > 00:20:00 ) do={
:put "Kicking $idletime - $mac"
/interface wireless registration-table remove [ /interface wireless registration-table find mac-address=$mac ]
}
}


Отключить неактивных более суток пользователей хотспота

:foreach i in=[/ip hotspot host find] do={
:local idletime [ /ip hotspot host get $i idle-time ]
:local mac [ /ip hotspot host get $i mac-address ]
:if ( $idletime > 24:00:00 ) do={
:put "Kicking $idletime - $mac"
/ip hotspot host remove [/ip hotspot host find mac-address=$mac]
}
}

Скрипт резервного подключения с ether1 на LTE-интерфейс:


/system script
add name=Main_UP owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
"/ip dhcp-client set [find interface=ether1] default-route-distance=1\r\
\n/ip dhcp-client set [find interface=lte1] default-route-distance=10"
add name=Main_DOWN owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=\
"/ip dhcp-client set [find interface=ether1] default-route-distance=10\r\
\n/ip dhcp-client set [find interface=lte1] default-route-distance=1"
/tool netwatch add down-script="/system script run Main_DOWN" host=8.8.4.4 interval=1s up-script="/system script run Main_UP"
/ip firewall filter add action=drop chain=input in-interface=!ether1 src-address=8.8.4.4


Отключить сессию если пользователь не прошел опрос:

:foreach i in=[/ip hotspot host find authorized=yes] do={
:local guestmac;
:local keyid;
:set guestmac [/ip hotspot host get $i mac-address ];
:set keyid [/ip hotspot host get $i server ];
:put "Checking $guestmac on Hotspot $keyid";
/tool fetch url="http://be.hot-wifi.ru/api/app/poll/bymac?keyid=$keyid&mac=$guestmac" dst-path="pollresult.$guestmac.txt";
:local pollresult [/file get "pollresult.$guestmac.txt" contents];
/file remove [/file find name="pollresult.$guestmac.txt"];
if ($pollresult = 0) do={
:put "KICKING $guestmac";
/ip hotspot host remove $i ;
}
}

Отключить сессию если пользователь не подключен в данный момент к wifi


:foreach i in=[/ip hotspot host find authorized=yes] do={
:local guestmac;
:local keyid;
:set guestmac [/ip hotspot host get $i mac-address ];
:set keyid [/ip hotspot host get $i server ];
:put "Checking $guestmac on Hotspot $keyid";
:local wifiregid;
:set wifiregid [/interface wireless registration-table find mac-address=$guestmac]
:put "ok";
:put "$wifiregid";
if ($wifiregid = "") do={
:put "KICKING $guestmac";
/ip hotspot host remove $i ;
}
}

Помогла ли вам статья?