afaik 'Alive' packets are sent back to the radius server with the updates. These are usually sent every 5min, but you can change that using either the MT Router or the Radius server. Otherwise the total session data will be sent with the Stop packet.can anybody answer on how check amount of upload/dwonload traffic with radius and pppoe users?
/ip firewall add name=accounting
/ip firewall rule accounting add comment=user2
/ip firewall rule accounting add action=passthrough
/ip firewall rule forward add jump-target=accounting
: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/1073741824)
:if ($traf>1) do={:log facility=System-Info message=("user" . $i .
" exceeded 1Gb limit!")}
}
/ip firewall rule accounting return
}
So let me see if I understand this at all or if im on the right track.
first thing to do is add a chainThat's rightCode: Select all/ip firewall add name=accounting
then set a comment for it called userN atm i have 2 users soNot quiteCode: Select all/ip firewall rule accounting add comment=user2
add passthrough action to the chain accountingFor each user, you need to add 1 rule with action=passthrough and comment=userN.Code: Select all/ip firewall rule accounting add action=passthrough
So, in case of two users assuming we use ip addresses to identify them:[/color]Code: Select all/ip firewall rule accounting add action=passthrough comment=user1 dst-address=1.1.1.1/32 /ip firewall rule accounting add action=passthrough comment=user2 dst-address=1.1.1.2/32
add a jump rule in forward to accountingJust do not forget that this rule should be above all others. Also add rule with action=return to the accounting chain, in order to process general firewall rules in forward.Code: Select all/ip firewall rule forward add jump-target=accounting
[/color]Code: Select all/ip firewall rule accounting add action=return
change the refferences of forward to accounting in the script provided
and addNote, that return rule is added before, not from the script.Code: Select all: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/1073741824) :if ($traf>1) do={:log facility=System-Info message=("user" . $i . " exceeded 1Gb limit!")} } }
Add this script to system scheduler to do periodical checks.
does that look right?
Help is greatly appriciated
/ip firewall rule accounting add action=passthrough comment=user1 dst-address=192.168.0.199/24
192.168.0.199/32
192.168.0.0/24
[admin@MikroTik] system script> /ip firewall rule forward print
Flags: X - disabled, I - invalid, D - dynamic
0 action=jump jump-target=accounting
1 ;;; limit access for unauthorized hotspot clients
in-interface=ether2 action=jump jump-target=hotspot-temp
2 ;;; account traffic for authorized hotspot clients
action=jump jump-target=hotspot
3 action=accept
[admin@MikroTik] system script> /ip firewall rule accounting print
Flags: X - disabled, I - invalid, D - dynamic
0 ;;; user1
dst-address=192.168.0.195/32 action=passthrough
1 action=return
[admin@MikroTik] system script> print
0 name="account_user_traffic"
source=":local sum; :local traf;\r\n:set sum 0\r\n/ip firewall rule
accounting{\r\n:foreach i in [find] do={:incr sum}\r\n:for i from=1
to=$sum do={\r\n:set traf [get [find comment=("user" . $i)]
bytes]\r\n:set traf ($traf/1073741824)\r\n:if ($traf>1) do={:log
facility=System-Info message=("user" . $i . " exceeded 1Gb
limit!")}\r\n}\r\n}"
owner="admin" policy=ftp,reboot,read,write,policy,test
last-started=feb/16/2005 13:58:27 run-count=5
: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 ($raf/1073741824)
:if ($traf>1) do={:log facility=System-Info message=("Limit-exceeded")}
}
}
There is one corrected string:script starts working except now it spits an error to the log script error: empty string value where some kind of specific value expected
here is my current scriptCode: Select all: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 ($raf/1073741824) :if ($traf>1) do={:log facility=System-Info message=("Limit-exceeded")} } }
:set traf ($traf/1073741824)
/system scheduler disable [find]
:local sum; :local traf;
:local limit
:set sum 0
:set traf 0
:set limit 5
/ip firewall rule user1 {
:foreach i in [find] do={:incr sum}
:for i from=1 to=$sum do={
:set traf ([get [find comment=("user" . $i)] bytes] + $traf)
}
:set traf ($traf/1073741824)
:set limit ($limit-$traf)
/tool e-mail send to=user1@example.com subject="You spend $traf GB. Beware! only $limit GB left :)"
}
:local sum; :local traf;
:local limit
:set sum 0
:set traf 0
:set limit 5
/ip firewall rule user1 {
:foreach i in [find] do={:incr sum}
:for i from=1 to=$sum do={
:set traf ([get [find comment=("user" . $i)] bytes] + $traf)
}}
:set traf ($traf/1073741824)
:set limit ($limit - $traf)
/tool e-mail send to=user1@example.com subject="You spend $traf GB. Beware! only $limit GB left :)"
:local sum; :local traf; :local limit;
:set sum 0; :set traf 0; :set limit 5;
/ip firewall rule user1 {:foreach i in [find] do={:incr sum}; :for i from=1 to=$sum do={:set traf ([get [find comment=("user" . $i)] bytes] + $traf)};}; :set traf ($traf/1073741824); :set limit ($limit - $traf); /tool e-mail send to=psi@mikrotik.com subject=("You spend " . $traf . " GB. Beware! only " . $limit . "GB left :)");
/queue simple add target-addresses=<address of host you want to limit> name="user1"
:local sum; :local traf;
:set sum 0
/queue simple{
:foreach i in [find] do={:incr sum}
:for i from=1 to=$sum do={
:set traf [get [find name=("user" . $i)] total-bytes]
:set traf ($traf/1073741824)
:if ($traf>1) do={
:log facility=System-Info message=("user" . $i . " exceeded 1Gb limit!");
set [find name=("user" . $i)] max-limit=64000
}
}
}
:local traf;
/queue simple
:for i from=10 to= 200 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= 64000/64000
}
}
: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= 64000/64000
}
}
: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
}
}
}
/queue simple; :foreach i in=[find] \
do={ \
:set sqName [get $i name]; \
# :set sqTotalAvgRate [get $i total-avg-rate]; \
:set sqTotalBytes [get $i total-bytes]; \
:set sqLevel [:find $sqName "\[LevelA\]"]; \
:if ($sqLevel >= 0) do={ \
set $i limit-at=32000/32000 max-limit=64000/64000 burst-threshold=48000/48000 burst-limit=128000/128000 burst-time=30/30; \
:if ($sqTotalBytes > 104857600) do = { \
set $i limit-at=24000/24000 max-limit=32000/32000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \
}; \
} else {
:set sqLevel [:find $sqName "\[LevelB\]"]; \
:if ($sqLevel >= 0) do={ \
set $i limit-at=64000/64000 max-limit=128000/128000 burst-threshold=78000/78000 burst-limit=256000/256000 burst-time=30/30; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set $i limit-at=64000/64000 max-limit=64000/64000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \
}; \
} else { \
:set sqLevel [:find $sqName "\[LevelC\]"]; \
:if ($sqLevel >= 0) do={ \
set $i limit-at=72000/72000 max-limit=256000/256000 burst-threshold=96000/96000 burst-limit=1000000/1000000 burst-time=30/30; \
:if ($sqTotalBytes > (3 * 104857600)) do = { \
set $i limit-at=72000/72000 max-limit=72000/72000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \
}; \
}; \
}; \
}; \
:if ($sqLevel >= 0) do { \
:put ([get $i name] . " : " . [get $i limit-at] . " : " . [get $i max-limit] . " : " . [get $i burst-limit] . " : " . [get $i burst-threshold] . " : " . [get $i burst-time]) ; \
}; \
}
/queue simple reset-counters
Hi, i use this code and works fine, but:Here it is what I came up with:
This scripts checks names of simple queues and if it finds [LevelA], [LevelB] or [LevelC] in name, it sets specified parameters. It also checks total-bytes and if limit is reached it sets different parameters for a queue.Code: Select all/queue simple; :foreach i in=[find] \ do={ \ :set sqName [get $i name]; \ # :set sqTotalAvgRate [get $i total-avg-rate]; \ :set sqTotalBytes [get $i total-bytes]; \ :set sqLevel [:find $sqName "\[LevelA\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=32000/32000 max-limit=64000/64000 burst-threshold=48000/48000 burst-limit=128000/128000 burst-time=30/30; \ :if ($sqTotalBytes > 104857600) do = { \ set $i limit-at=24000/24000 max-limit=32000/32000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ } else { :set sqLevel [:find $sqName "\[LevelB\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=64000/64000 max-limit=128000/128000 burst-threshold=78000/78000 burst-limit=256000/256000 burst-time=30/30; \ :if ($sqTotalBytes > (2 * 104857600)) do = { \ set $i limit-at=64000/64000 max-limit=64000/64000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ } else { \ :set sqLevel [:find $sqName "\[LevelC\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=72000/72000 max-limit=256000/256000 burst-threshold=96000/96000 burst-limit=1000000/1000000 burst-time=30/30; \ :if ($sqTotalBytes > (3 * 104857600)) do = { \ set $i limit-at=72000/72000 max-limit=72000/72000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ }; \ }; \ }; \ :if ($sqLevel >= 0) do { \ :put ([get $i name] . " : " . [get $i limit-at] . " : " . [get $i max-limit] . " : " . [get $i burst-limit] . " : " . [get $i burst-threshold] . " : " . [get $i burst-time]) ; \ }; \ }
This allows you to set groups at will (it is easily expandable to needed number of groups, these three are just for an example) and easily put queue in needed group by entering group ID within name. This means you may keep custom simple queue names, just add Group ID in it.
If you want to change group for some simple queue, just change group id in that queue name.
As previosu script, this script should be scheduled in regular time periods, for instance every 5 minutes, and also there should be triger that resets total-bytes once a day. REcomendation is that reset is done about 2 AM.
Script runs but this is my the very frst MT script for so it is possible it is not of greatest quality code. I hope som of experienced members will suggest if there are possible improvements in code.
How to reset counters:Code: Select all/queue simple reset-counters
Hi, i use this code and works fine, but:Here it is what I came up with:
This scripts checks names of simple queues and if it finds [LevelA], [LevelB] or [LevelC] in name, it sets specified parameters. It also checks total-bytes and if limit is reached it sets different parameters for a queue.Code: Select all/queue simple; :foreach i in=[find] \ do={ \ :set sqName [get $i name]; \ # :set sqTotalAvgRate [get $i total-avg-rate]; \ :set sqTotalBytes [get $i total-bytes]; \ :set sqLevel [:find $sqName "\[LevelA\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=32000/32000 max-limit=64000/64000 burst-threshold=48000/48000 burst-limit=128000/128000 burst-time=30/30; \ :if ($sqTotalBytes > 104857600) do = { \ set $i limit-at=24000/24000 max-limit=32000/32000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ } else { :set sqLevel [:find $sqName "\[LevelB\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=64000/64000 max-limit=128000/128000 burst-threshold=78000/78000 burst-limit=256000/256000 burst-time=30/30; \ :if ($sqTotalBytes > (2 * 104857600)) do = { \ set $i limit-at=64000/64000 max-limit=64000/64000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ } else { \ :set sqLevel [:find $sqName "\[LevelC\]"]; \ :if ($sqLevel >= 0) do={ \ set $i limit-at=72000/72000 max-limit=256000/256000 burst-threshold=96000/96000 burst-limit=1000000/1000000 burst-time=30/30; \ :if ($sqTotalBytes > (3 * 104857600)) do = { \ set $i limit-at=72000/72000 max-limit=72000/72000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \ }; \ }; \ }; \ }; \ :if ($sqLevel >= 0) do { \ :put ([get $i name] . " : " . [get $i limit-at] . " : " . [get $i max-limit] . " : " . [get $i burst-limit] . " : " . [get $i burst-threshold] . " : " . [get $i burst-time]) ; \ }; \ }
This allows you to set groups at will (it is easily expandable to needed number of groups, these three are just for an example) and easily put queue in needed group by entering group ID within name. This means you may keep custom simple queue names, just add Group ID in it.
If you want to change group for some simple queue, just change group id in that queue name.
As previosu script, this script should be scheduled in regular time periods, for instance every 5 minutes, and also there should be triger that resets total-bytes once a day. REcomendation is that reset is done about 2 AM.
Script runs but this is my the very frst MT script for so it is possible it is not of greatest quality code. I hope som of experienced members will suggest if there are possible improvements in code.
How to reset counters:Code: Select all/queue simple reset-counters
I have a simmilar problem. My isp gives me certain volume of data monthly to use, and i want to shape my network to allow my clients (20 of them) to be able to stay within the volume given by my ISP. I have seen this post in the forum and it suits my needs, but am new to scripting. How do i add a scheduler for 5 minutes to this event which you just gave a code for??Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
I have a simmilar problem. My isp gives me certain volume of data monthly to use, and i want to shape my network to allow my clients (20 of them) to be able to stay within the volume given by my ISP. I have seen this post in the forum and it suits my needs, but am new to scripting. How do i add a scheduler for 5 minutes to this event which you just gave a code for??Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
I have a simmilar problem. My isp gives me certain volume of data monthly to use, and i want to shape my network to allow my clients (20 of them) to be able to stay within the volume given by my ISP. I have seen this post in the forum and it suits my needs, but am unable to see any changes after i specified a limit of 5242880. i want a 5MB download limit....??Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
I have a simmilar problem. My isp gives me certain volume of data monthly to use, and i want to shape my network to allow my clients (20 of them) to be able to stay within the volume given by my ISP. I have seen this post in the forum and it suits my needs, but am unable to see any changes after i specified a limit of 5242880. i want a 5MB download limit....??Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
I have a simmilar problem. My isp gives me certain volume of data monthly to use, and i want to shape my network to allow my clients (20 of them) to be able to stay within the volume given by my ISP. I have seen this post in the forum and it suits my needs, but am unable to see any changes after i specified a limit of 5242880. i want a 5MB download limit....??Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
Hi, I am not a programmer and have never attempted any script in my entire life. I don't know how to do it correctly. Will the following work???Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
I 2 have tried this script and have even set the limits way low like 60K and users are suppose to be down to like 10k both ways but I dont see this rule being applied....all my clients have ip starting in the 10.5.50 range so I changed to these settings in the script. Any long awaited input would be great here... this compatible with 2.9.43?i have implemented this rule in my schedule, but somehow, when the total bytes transferred gets to 5MB, the schedule does not take the upload/download to 16000/32000... Is there anything else i need to do?
this is my configuration..
/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 > 5242880) do = {
set [find target-addresses=("192.168.1." . $i)] max-limit= 16000/32000
}
}
}
Does this work for usermanager accounts?Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
/system script
add name=start_limit source={/system scheduler name=limiter_timer start-time=18:00:00 interval=5m script=limiter}
add name=stop_limit source={!!!!How do i remove the scheduler?... I have yet to buy/ever use microTik but will the moment once I get the hardware I plan to use. The PC I bought has a sata controller not supported so I have ordered another. Something like "/system scheduler remove limiter_timer" is my guess
/que simple reset-counters
}
/ system scheduler
add name=start_limit_script start-time=18:00:00 interval=24h script=start_limit
add name=stop_limit_script start-time=23:25:00 interval=24h script=stop_limit
/system script limiter {
:local traf;
/queue simple
{
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.100.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.100.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.100.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.101.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.101.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.101.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.102.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.102.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.102.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.103.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.103.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.103.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.151.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.151.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.151.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.152.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.152.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.152.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.153.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.153.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.153.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.154.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.154.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.154.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.155.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.155.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.155.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.156.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.156.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.156.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.157.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.157.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.157.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.158.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.158.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.158.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.159.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.159.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.159.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.160.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.160.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.160.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.161.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.161.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.161.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.162.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.162.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.162.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.163.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.163.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.163.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.164.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.164.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.164.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.165.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.165.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.165.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.166.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.166.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.1.166." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.167.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.167.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.167.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.168.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.168.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.168.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.169.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.169.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.169.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.170.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.170.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.170.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.171.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.171.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.171.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.172.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.172.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.172.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.173.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.173.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.173.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.174.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.174.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.174.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.175.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.175.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.175.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.176.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.176.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.176.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.177.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.177.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.177.1." . $i)] max-limit= 32000/64000
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.178.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.178.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.178.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.179.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.179.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.179.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.181.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.181.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.181.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.182.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.182.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.182.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.183.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.183.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.183.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.184.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.184.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.184.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.185.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.185.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.185.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.186.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.186.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.186.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.187.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.187.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.187.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.188.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.188.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.188.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.189.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.189.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.189.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:if ([/queue simple find target-addresses=("10.140.1." . $i)] != "") do={
:set traf [get [find target-addresses=("10.140.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.140.1." . $i)] max-limit= 32000/64000
}
}
}
:for i from=1 to= 254 do = {
:for j from=0 to= 63 do = {
:if ([/queue simple find target-addresses=("10.150." . $j . "." . $i)] != "") do={
:set traf [get [find target-addresses=("10.150.1." . $i)] total-bytes]
:if ($traf > 524288000) do = {
set [find target-addresses=("10.150.1." . $i)] max-limit= 32000/64000
}
}
}
}
}
}
And this is my schedulerName : shapingRate
:local traf;
/queue simple
:for i from= 1 to= 254 do = {
:if ([/queue simple find target-addresses=("192.168.88." . $i)] != "") do={
:set traf [get [find target-addresses=("192.168.88." . $i)] total-bytes]
:if ($traf > 10485760) do = {
set [find target-addresses=("192.168.88." . $i)] max-limit= 10240/10240
}
}
}
Name : run-1h
/que simple reset-counters
Name : run-24h
resetCounter
/queue simple; :foreach i in=[find] \
do={ \
:set sqName [get $i name]; \
# :set sqTotalAvgRate [get $i total-avg-rate]; \
:set sqTotalBytes [get $i total-bytes]; \
:set sqLevel [:find $sqName "\[BASE-R\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=256K/10M; \
:if ($sqTotalBytes > 104857) do = { \
set $i max-limit=256K/1280K; \
}; \
} else {
:set sqLevel [:find $sqName "\[STANDARD-R\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=256K/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set $i max-limit=256K/2304K; \
}; \
} else { \
:set sqLevel [:find $sqName "\[PLUS-R\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=512K/10M; \
:if ($sqTotalBytes > (3 * 104857600)) do = { \
set $i max-limit=512K/3M; \
}; \
} else {
:set sqLevel [:find $sqName "\[TOP-R\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=512K/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set set $i max-limit=512K/4M; \
}; \
} else {
:set sqLevel [:find $sqName "\[EXTREME-R\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=1M/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set set $i max-limit=1M/7M; \
}; \
} else {
:set sqLevel [:find $sqName "\[BASE-B\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=256K/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set $i max-limit=256K/1280K; \
}; \
} else {
:set sqLevel [:find $sqName "\[STANDARD-B\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=320K/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set set $i max-limit=320K/2304k; \
}; \
} else {
:set sqLevel [:find $sqName "\[TOP-B\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=512k/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set set $i max-limit=512K/4M; \
}; \
} else {
:set sqLevel [:find $sqName "\[EXTEME-B\]"]; \
:if ($sqLevel >= 0) do={ \
set $i max-limit=1M/10M; \
:if ($sqTotalBytes > (2 * 104857600)) do = { \
set set $i max-limit=1M/7M; \
}; \
}; \
}; \
}; \
:if ($sqLevel >= 0) do { \
:put ([get $i name] . " : " . [get $i limit-at] . " : " . [get $i max-limit] . " : " . [get $i burst-limit] . " : " . [get $i burst-threshold] . " : " . [get $i burst-time]) ; \
}; \
}
what os version work with this script ?Thank you very much,
Now I can give the service i wanted to offer.
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 give greater speads, cose the network is slightly used.
For the others information here is the complete script that is tested and works.
Code: Select all: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".
Mnthanks bro,Many times people have asked how to shape traffic based on the amount the user has already downloaded.
Here is a small script which makes 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)
The original can be found in MT docs:
http://www.mikrotik.com/docs/ros/2.8/ap ... t#11.2.5.8