modified on 29 October 2007 at 10:47 ••• 17,387 views

Limiting a user to a given amount of traffic

From MikroTik Wiki

Jump to: navigation, search

Many times people have asked how to shape traffic based on the amount the user has already downloaded. Here is a small script which does the job:

: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/1073741824)
:if ($traf>1) do={:log facility=System-Info message=("user" . $i .
" exceeded 1Gb limit!")}
}
}

Comments:

  1. Make your own chain for accounting purposes (just don't forget to add jumps from forward chain.) In the end of this chain add return rule.
  2. Make a custom action when the user reaches the limit. By default the scripts writes message to logs (use /log print without-paging command to view logs)
  3. This script can also work with PPPoE. Just make correct firewall rules that count traffic for particular PPPoE client.

External Links

See also