Difference between revisions of "Limiting a user to a given amount of traffic II"

From MikroTik Wiki
Jump to: navigation, search
(External Links)
 
(13 intermediate revisions by 6 users not shown)
Line 2: Line 2:
 
And i have users that would download the whole internet in a day if they could.
 
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.
 
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 give greater speads, cose the network is slightly used.
+
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.
 
For the others information here is the complete script that is tested and works.
Line 18: Line 18:
  
 
This script will check all the simple queues shearching their target adresses and will search a whole 192.168.1.0/24 subnet.
 
This script will check all the simple queues shearching their target adresses and will search a whole 192.168.1.0/24 subnet.
It will read their total-bytes (recieved + transmited) and will check them if they crosed a limit of 100 MB ( 104857600 bytes)
+
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)
 
If they did , they will be limited to lower speed (64k/64k)
  
Line 27: Line 27:
  
 
==Limitations==
 
==Limitations==
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 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?<br>
==See also==
+
If a similiar script were to be applied to a pppoe style connection, a simple disconnection by the user would reset the traffic counters.
*[[Limiting a user to a given amount of traffic]]
+
 
 +
==External Links==
 +
*[http://forum.mikrotik.com/viewtopic.php?t=308 MikroTik Forum]
 +
 
 +
[[Category:Scripting]]

Latest revision as of 01:36, 18 July 2010

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 192.168.1.0/24 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".

Limitations

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