我想将用户下载的字节值(tx-bytes,rx-bytes)与我的模式进行比较(例如100MiB,50MiB) 但我不能写脚本来解决这个问题,我怎么能这样做呢?
我想写脚本的地方是:/ interface wireless registration-table> tx-rx字节值 (an image of this Place)
答案 0 :(得分:1)
如您所述,您可以使用 / interface wireless registration-table 查询注册表。将它放在脚本循环上会给出
:foreach wirelessClient in [/interface wireless registration-table find true] do={}
然后,在这个foreach循环中,使用id获取每个客户端的统计信息(这里的例子是“mac-address”和“bytes”字段)
:local macAddress [/interface wireless registration-table get [ find .id=$wirelessClient ] value-name=mac-address];
:local bytes [/interface wireless registration-table get [ find .id=$wirelessClient ] value-name=bytes];
返回的“字节”数据格式为“RX,TX”(即“545124,25422”)。所以你必须做一个小技巧来提取RX字符串:在这个逗号之前查找“,”字符和提取字符串。
:local posComma [ :find $bytes "," -1]
:local RXbytes [:pick $bytes 0 $posComma]
然后,很容易检查该客户端是否已下载超过50M
:local status "Below 50M";
:if ($RXbytes > 50000000) do={
:set $status "Above 50M"
}
:put "Client: $macAddress $bytes $RXbytes -> $status";
将所有内容放在脚本中并执行它,您将获得类似
的内容[foo@bar] > import test.rsc
Client: D4:CA:6D:B2:AE:EF 202134,92985 202134 -> Below 50M
Client: 48:9D:24:64:E6:08 8057465,2022134 8057465 -> Below 50M
Client: 2C:56:DC:32:09:F0 3282973,888408 3282973 -> Below 50M
Client: 48:59:29:F6:DF:5D 139664,248984 139664 -> Below 50M
Client: A4:5E:60:EB:AE:33 159890028,12433385 159890028 -> Above 50M
有关完整的Mikrotik脚本手册,请查看http://wiki.mikrotik.com/wiki/Manual:Scripting