Hey guys, I have written a script to measure the traffic usage of one of my wireless client and I need an expert opinion on my code. It seems to work, but I wanna know if my approach is correct and if there’s any way to improve it.
The logic of my code is, first it gets the Bytes parameter from registration-table for that specific client. Then it adds sent and received bytes and write it to a file named as consumption.txt which I have created on my router. I reset the statistic for that specific client before I activate the code and whenever the traffic usage crosses the limit (in my case 4GB), the client no longer has access to wireless network.
Here’s the script:
{
:global previousConsumption [/file get consumption.txt contents];
:tonum $previousConsumption;
:global subjectTraffic [/interface wireless registration-table get [find mac-address=xx:xx:xx:xx:xx:xx] bytes];
:global substringPosition [:find $subjectTraffic “,”];
:global subjectLength [:len $subjectTraffic];
:global a [:pick $subjectTraffic 0 $substringPosition];
:tonum $a;
:global b [:pick $subjectTraffic ($substringPosition+1) $subjectLength];
:tonum $b;
:if ($previousConsumption !=“”) do={
:global consumption ($a+$b+$previousConsumption)
} else={
:global consumption ($a+$b)
}
:file set consumption.txt contents=$consumption;
if ($consumption > 4294967296) do={
int wireless access-list add mac-address=xx:xx:xx:xx:xx:xx authentication=no;
}
}