traffic limiting using your script

Hi, I created the rule to forward to accounting, then created one user with dst-address being his IP and comment = user1. I copied and paste the script you supplied to scheduler (winbox) and set it to run every 5seconds to test. I used the script below:

:local sum; :local traf;
:set sum 0
/ip firewall rule forward {
:foreach i in [find] do={:incr sum}
:for i from=1 to=$sum do={
:set traf [get [find comment=(“user” . $i)]
bytes]
:set traf ($traf/1)
:if ($traf>1) do={:log facility=System-Info message=(“user” . $i .
" exceeded 1Gb limit!")}
}
}

I made the set traf ($traf/1) to test it, i will later set it to 1Gb.

my problem: nothing is showing in my log. the traffic is registering next to the IP in the filter window (winbox) so up to there its fine, any ideas?

what is your Router/Os version?

if it is 2.9.x correct your line:

:if ($traf>1) do={:log info ("user" . $i . " exceeded 1Gb limit!")}

Regards

Yes 2.9.46
I did the change…still nothing. Also the under the run count under scripts in winbox when I click run script it doesn’t increase

:local sum; :local traf; 
:set sum 0 
/ip firewall rule accounting { 
:foreach i in [find] do={:incr sum} 
:for i from=1 to=$sum do={ 
:set traf [get [find comment=("user" . $i)] 
bytes] 
:set traf ($traf/1) 
:if ($traf>1) do={:log info ("user" . $i . " exceeded 1Gb limit!")}
} 
}

Any other ideas? I created an accounting chain, ran through all the IPs used in my network and then return chain. For some reason the script doesn’t want to execute.

yeh thats true, the script is for old version!
any how i’v fixed it for you but dont forget to adjust the value of “users” depend on how many users you have, also dont forget to change $traf/1 to $traf/1073741824

:local users
:local traf
:local i
:set users 1
/ip fire filter
:for i from=1 to=$users do={ 
:set traf [get [/ip fire filter find comm ("user" . $i)] bytes] 
:set traf ($traf/1) 
:if ($traf>1) do={:log info ("user" . $i . " exceeded 1Gb limit!")}
}

Regards.

Wow dude… :astonished: finally it works! after months of queries and no one replies…not even the sys admins!

Thanx dude, the users etc piece of cake

You are welcome man, and good luck.