Limiting a user to a given amount of traffic II

From MikroTik Wiki
Revision as of 13:40, 17 July 2010 by Dr-root (talk | contribs) (good Modified for limiting the user traffic by queue)
Jump to: navigation, search

I have users that never spend 100 mb daily but need the good speed, And i have users that would download the whole internet in a day if they could. This way 'easy' users will have good speed for browsing , chatting with camera, and some small downloads. And the 'bandwidth hungry' users will suffer slower speeds after they cross their 100MB during the day. But, thats not that bad , users can download during the night hours 1am-10am when I disable this script and allow higher speed, because the network is not at peak usage.

For the others information here is the complete script that is tested and works.

:local traf;
/queue simple
  :for i from=1 to= 254 do =  {
    :if ([/queue simple find target-addresses=("192.168.1." . $i)] != "") do={
      :set traf [get [find target-addresses=("192.168.1." . $i)] total-bytes]
      :if ($traf  > 104857600) do = {
        set [find target-addresses=("192.168.1." . $i)] max-limit= 32000/64000

This script will check all the simple queues shearching their target adresses and will search a whole subnet. It will read their total-bytes (recieved transmited) and will check them if they crosed a limit of 100 MB ( 104857600 bytes) If they did , they will be limited to lower speed (64k/64k)

You can change the subnet, the limit, and the lower speed acording to your needs.

It shoud be added a scheduler that will run this script every 5 minutes or so. Another scheduler to reset counters daily " /que simple reset-counters".


If the MT box is reset the traffic counters will be reset and the speed will return to normal (e.g. power outage) -- someone confirm this?
If a similiar script were to be applied to a pppoe style connection, a simple disconnection by the user would reset the traffic counters.

External Links

good Modified for limiting the user traffic by queue good job man I could amendment written by and to act as follows when one is to download a 50 MB landing speeds for less than specified if it continued to load and carry up to 100 MB will fall more if it continues to load will fall more and more until it becomes 64 Kbps I am sorry I am weak in English Please members of the drafting of the amendment properly thanks for all

local traf;

/queue simple

 :for i from=1 to= 254 do =  {
   :if ([/queue simple find target-addresses=("192.168.3." . $i)] != "") do={
     :set traf [get [find target-addresses=("192.168.3." . $i)] total-bytes]
     :if ($traf  < 1073741824) do = {
       set [find target-addresses=("192.168.3." . $i)] max-limit= 256000/1024000
:if ($traf  > 52428800) do = {
if ($traf < 62428800) do = {
       set [find target-addresses=("192.168.3." . $i)] max-limit= 256000/400000 
:if ($traf  > 104857600) do = {
if ($traf < 114857600) do = {
       set [find target-addresses=("192.168.3." . $i)] max-limit= 200000/200000 
:if ($traf  > 157286400) do = {
if ($traf < 167286400) do = {
       set [find target-addresses=("192.168.3." . $i)] max-limit= 128000/128000   
if ($traf > 209715200) do = {
if ($traf < 229715200) do = {
       set [find target-addresses=("192.168.3." . $i)] max-limit= 64000/64000