Community discussions

MikroTik App
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

hotspot & queues user speed limit after x download scripts

Fri Jun 03, 2016 3:27 pm

in user list bytes in and out doesn't count unless user log out and login back can anyone help me to make it count while user active or we can make script read active user statics bytes

am tryingg to limit user according to download this is the script i am trying to make it read active user bytes out and in but i couldn't   originally written by Deantwo
 
/ip hotspot user {
    :local limitedProfile "4m"
    :local limitedSlowProfile "LimitedSlow4"
    :local trafLimit 7516192768

    :local userList [find profile=$limitedProfile]
    :foreach user in=$userList do={
        :local traf ([get $user bytes-in] + [get $user bytes-out])
        :put ("User (" . [get $user name] . ") traf: " . $traf)
        :if ($traf > $trafLimit) do={
            set $user profile=$limitedSlowProfile
            :put ("User (" . [get $user name] . ") reached the traf limit")
            :log warning ("User (" . [get $user name] . ") reached the traf limit")
        }
    }
}
Last edited by AYcoo on Thu Aug 18, 2016 6:00 am, edited 5 times in total.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Fri Jun 03, 2016 4:33 pm

please anyone
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: how to make user bytes out statistics calculate with active user

Sun Jun 05, 2016 7:21 am

I dont understand what do you want exactly, when user reach the total limit it will automatically remove from the active, do you want when the user reach the total limit it will change his profile to slower one ?
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Sun Jun 05, 2016 7:26 am

I dont understand what do you want exactly, when user reach the total limit it will automatically remove from the active, do you want when the user reach the total limit it will change his profile to slower one ?
what i want is that user profile change to the slower one immidiatly when he reach the limit with out log out
and thank u for replying to me :)
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Sun Jun 05, 2016 5:35 pm

or we can kick only users who reached the limit is it possible ?
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 06, 2016 12:57 pm

>>> please anyone can help
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: how to make user bytes out statistics calculate with active user

Tue Jun 07, 2016 1:24 pm

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Tue Jun 07, 2016 1:31 pm

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
the script above already identify user who reach limit and i use this script to kick them all
:foreach i in=[/ip hotspot active find]  do={
/ip hotspot active remove $i
}
but this is not what i want
what i want is :
user who reach limit only get kicked and change his profile to slower
user who didn't reach limit remain connected and active
can u do that ?
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: how to make user bytes out statistics calculate with active user

Wed Jun 08, 2016 12:26 am

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
the script above already identify user who reach limit and i use this script to kick them all
:foreach i in=[/ip hotspot active find]  do={
/ip hotspot active remove $i
}
but this is not what i want
what i want is :
user who reach limit only get kicked and change his profile to slower
user who didn't reach limit remain connected and active
can u do that ?
it easy i ll do it soon ...
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Wed Jun 08, 2016 1:15 am

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
the script above already identify user who reach limit and i use this script to kick them all
:foreach i in=[/ip hotspot active find]  do={
/ip hotspot active remove $i
}
but this is not what i want
what i want is :
user who reach limit only get kicked and change his profile to slower
user who didn't reach limit remain connected and active
can u do that ?
it easy i ll do it soon ...
thank u so much waiting you :)
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Thu Jun 09, 2016 3:07 pm

...up
 
User avatar
Sinan
Trainer
Trainer
Posts: 129
Joined: Tue Sep 01, 2015 7:00 am

Re: how to make user bytes out statistics calculate with active user

Sat Jun 11, 2016 12:52 pm

First you limit the amount of the user in limit-bytes-total or out ..
Then in the Fast-speed profile at script on-logout put this script:
{
:if ($cause="traffic limit reached") do={
/ip hotspot user set profile="profile2" [find name="$user"]
/ip hotspot user reset-counters [find name="$user"]
}}
change profile2 to the name of the slow-speed profile
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Sat Jun 11, 2016 1:07 pm

First you limit the amount of the user in limit-bytes-total or out ..
Then in the Fast-speed profile at script on-logout put this script:
{
:if ($cause="traffic limit reached") do={
/ip hotspot user set profile="profile2" [find name="$user"]
/ip hotspot user reset-counters [find name="$user"]
}}
change profile2 to the name of the slow-speed profile
i am testing now
Last edited by AYcoo on Sat Jun 11, 2016 2:37 pm, edited 1 time in total.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Sat Jun 11, 2016 1:46 pm

First you limit the amount of the user in limit-bytes-total or out ..
Then in the Fast-speed profile at script on-logout put this script:
{
:if ($cause="traffic limit reached") do={
/ip hotspot user set profile="profile2" [find name="$user"]
/ip hotspot user reset-counters [find name="$user"]
}}
change profile2 to the name of the slow-speed profile
what happen is that user didn't logout after reaching limit he continued active

i think the best solution for all of this is to make users statistics work along with active statistics counters 
the problem is user counters doesn't work unless user log out and back again 
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Sat Jun 11, 2016 5:50 pm

i have been trying to do script that identfy active user download byte and change his prfile if he reach limit 

but didn't work 
/ip hotspot user {

    :local limitedProfile "2m"  
    :local limitedSlowProfile "LimitedSlow2"
    :local trafLimit 314572800                   
                          
     :local userList [find profile=$limitedProfile]
     :foreach counter in=[/ip hotspot active find ] do={
        :local traf ([/ip hotspot active get $counter bytes-in] + [/ip hotspot active get $counter bytes-out])
           :foreach user in=$userList do={                                                   
         :put ("User (" . [get $user name] . ") traf: " . $traf)
        :if ($traf > $trafLimit) do={                          
          set $user profile=$limitedSlowProfile
            :put ("User (" . [get $user name] . ") reached the traf limit")
            :log warning ("User (" . [get $user name] . ") reached the traf limit")
           }                                                                    
        }
   }     
}   

 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 10:58 am

I don't have a way to test "hotspot active user" values, hence why the script I wrote uses the "hotspot user" values.

From what I can see "hotspot active user" has a "user" value with the username of the user. So making the script check that user and/or log out that user shouldn't be that hard.

Things I don't know is rather the "hotspot active user" byte values are for that one session or a total for that user.
For example if a user login, download 5 bytes, then logout and login again and then download another 7 bytes. what will each counter say?
My guess is that the "hotspot user" user will say 5 bytes and the "hotspot active user" will say 7 bytes. But I would like for you to possibly test this out for me.

Let me try to update this a little bit at least.
# Checks if limited users has reached the limit, if they have then set them to be limited slow state.
# Run this script every few minutes.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
    :local trafLimit 10000
# Code:
    :local userList [find profile=$limitedProfile]
    :foreach user in=$userList do={
        :local traf ([get $user bytes-in] + [get $user bytes-out])
        :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
        :if ([:len $activeUser] != 0) do={
            :set traf ($traf + [/ip hotspot active get $activeUser bytes-in] + [/ip hotspot active get $activeUser bytes-out])
        }
        :put ("User (" . [get $user name] . ") traf: " . $traf)
        :if ($traf > $trafLimit) do={
            set $user profile=$limitedSlowProfile
            :put ("User (" . [get $user name] . ") reached the traf limit")
            :if ([:len $activeUser] != 0) do={
                /ip hotspot active remove $activeUser
                :put ("User (" . [get $user name] . ") has been forcefully logged out")
            }
            :log warning ("User (" . [get $user name] . ") reached the traf limit")
        }
    }
}
# Reset counts are the limited users.
# Run this script once every day.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
# Code:
    :foreach user in=[find (profile=$limitedProfile || profile=$limitedSlowProfile)] do={
        /ip hotspot active remove [/ip hotspot active find user=[/ip hotspot user get $user name]]
    }
    reset-counters [find (profile=$limitedProfile || profile=$limitedSlowProfile)]
    set [find profile=$limitedSlowProfile] profile=$limitedProfile
    :log warning "All user limits has been reset"
}
This may work better, it is untested on a live system though.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 1:21 pm

I don't have a way to test "hotspot active user" values, hence why the script I wrote uses the "hotspot user" values.

From what I can see "hotspot active user" has a "user" value with the username of the user. So making the script check that user and/or log out that user shouldn't be that hard.

Things I don't know is rather the "hotspot active user" byte values are for that one session or a total for that user.
For example if a user login, download 5 bytes, then logout and login again and then download another 7 bytes. what will each counter say?
My guess is that the "hotspot user" user will say 5 bytes and the "hotspot active user" will say 7 bytes. But I would like for you to possibly test this out for me.

Let me try to update this a little bit at least.
# Checks if limited users has reached the limit, if they have then set them to be limited slow state.
# Run this script every few minutes.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
    :local trafLimit 10000
# Code:
    :local userList [find profile=$limitedProfile]
    :foreach user in=$userList do={
        :local traf ([get $user bytes-in] + [get $user bytes-out])
        :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
        :if ([:len $activeUser] != 0) do={
            :set traf ($traf + [/ip hotspot active get $activeUser bytes-in] + [/ip hotspot active get $activeUser bytes-out])
        }
        :put ("User (" . [get $user name] . ") traf: " . $traf)
        :if ($traf > $trafLimit) do={
            set $user profile=$limitedSlowProfile
            :put ("User (" . [get $user name] . ") reached the traf limit")
            :if ([:len $activeUser] != 0) do={
                /ip hotspot active remove $activeUser
                :put ("User (" . [get $user name] . ") has been forcefully logged out")
            }
            :log warning ("User (" . [get $user name] . ") reached the traf limit")
        }
    }
}
# Reset counts are the limited users.
# Run this script once every day.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
# Code:
    :foreach user in=[find (profile=$limitedProfile || profile=$limitedSlowProfile)] do={
        /ip hotspot active remove [/ip hotspot active find user=[/ip hotspot user get $user name]]
    }
    reset-counters [find (profile=$limitedProfile || profile=$limitedSlowProfile)]
    set [find profile=$limitedSlowProfile] profile=$limitedProfile
    :log warning "All user limits has been reset"
}
This may work better, it is untested on a live system though.
first thank u for replaying :)  
the user log in then the active counter start counting what is user is downloading -right now user value is 0 total bytes- let say he download 1 gig  , when he log out this 1 gig will go to the user value statistics . if he login again active counter will start over again from 0
see attachment will demonstrate  u will see user majed11 is active he download 600 mb but his user counters are 0 if force him log out what he download in active counters will move to user counters
+
i tried the script u wrote sadly it didn't work (invalid internal item number)
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 3:15 pm

Things I don't know is rather the "hotspot active user" byte values are for that one session or a total for that user.
For example if a user login, download 5 bytes, then logout and login again and then download another 7 bytes. what will each counter say?
My guess is that the "hotspot user" user will say 5 bytes and the "hotspot active user" will say 7 bytes. But I would like for you to possibly test this out for me.
Found a nice little way to test this, and it seems that I was correct. So my script should be handling that correctly.
i tried the script u wrote sadly it didn't work (invalid internal item number)
Ok, I don't know why the script fails on your end, I don't have that issue in my tests.
Not doing anything in the script that should make it possible for invalid find results.

Only thing I can think of is if multiple active users have the same name, but that makes little sense.
Could also be a user logout at the exact moment the script was running, but that is just unlikely.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 3:39 pm

Things I don't know is rather the "hotspot active user" byte values are for that one session or a total for that user.
For example if a user login, download 5 bytes, then logout and login again and then download another 7 bytes. what will each counter say?
My guess is that the "hotspot user" user will say 5 bytes and the "hotspot active user" will say 7 bytes. But I would like for you to possibly test this out for me.
Found a nice little way to test this, and it seems that I was correct. So my script should be handling that correctly.
i tried the script u wrote sadly it didn't work (invalid internal item number)
Ok, I don't know why the script fails on your end, I don't have that issue in my tests.
Not doing anything in the script that should make it possible for invalid find results.

Only thing I can think of is if multiple active users have the same name, but that makes little sense.
Could also be a user logout at the exact moment the script was running, but that is just unlikely.
i tested it many times the same error hmmm  :? all active user have different names  i have two routers i tested it in both , can any one try this maybe he will get different result 
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 3:52 pm

i have two routers i tested it in both , can any one try this maybe he will get difference result 
Can you try running this and giving me the result if it fails?
# Variables:
:global limitedProfile "Limited"
# Code:
/ip hotspot user {
    :local userList [find profile=$limitedProfile]
    :put $userList
}
:put [/ip hotspot active find user=[/ip hotspot user get [:pick [find profile=$limitedProfile] 0] name]]
/ip hotspot user {
    :local userList [find profile=$limitedProfile]
    :foreach user in=$userList do={
        :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
        :if ([:len $activeUser] != 0) do={
            :put $activeUser
        }
    }
}
:global limitedProfile
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user

Mon Jun 13, 2016 3:58 pm

i have two routers i tested it in both , can any one try this maybe he will get difference result 
Can you try running this and giving me the result if it fails?
You do not have the required permissions to view the files attached to this post.
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 4:14 pm

[localhost] /ip hotspot user> # Variables:
[localhost] /ip hotspot user> :global limitedProfile "Limited"
[localhost] /ip hotspot user> # Code:
[localhost] /ip hotspot user> /ip hotspot user {
{...     :local userList [find profile=$limitedProfile]
{...     :foreach user in=$userList do={
{{...         :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
{{...         :if ([:len $activeUser] != 0) do={
{{{...             :put ("user: " . [/ip hotspot user get $user name])
{{{...             :put ("active: " . [/ip hotspot active get $activeUser user])
{{{...         }
{{...     }
{... }
user: user1
active: user1
user: user2
active: user1
[localhost] /ip hotspot user> :global limitedProfile
How the bloody hell does this make any sense.
Why am I getting the incorrect active users from [/ip hotspot active find user=[/ip hotspot user get $user name]] with a non-login user?

I am gonna do some testing. At least now I know what the issue is, now I just need to figure out why the issue is there to begin with.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 4:36 pm

Tested code from the last post on v6.34.5. Works as it should.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 4:44 pm

Tested code from the last post on v6.34.5. Works as it should.
do you think the problem is with my current version 6.30.4 ,so i should update ?
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 4:52 pm

Tested code from the last post on v6.34.5. Works as it should.
I am testing on v6.35, but having weird result from the foreach while the loop variable is named "user".
If I change the name of the variable to "t" it works as expected.

Can you try this:
  1. I have two users "user1" and "user2"
  2. Both users have profile "Limited"
  3. "user1" is logged in and listed in "/ip hotspot active"
/ip hotspot user {
    :local userList [find profile="Limited"]
    :put [:len $userList]
    :put $userList
    :put "- foreach start -"
    :foreach user in=$userList do={
        :put [:len $user]
        :put $user
        :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
        :put [:len $activeUser]
        :if ([:len $activeUser] != 0) do={
            :put $activeUser
            :put ("user: " . [/ip hotspot user get $user name])
            :put ("active: " . [/ip hotspot active get $activeUser user])
        }
        :put "- continue -"
    }
    :put "- done -"
}
/ip hotspot user {
    :local userList [find profile="Limited"]
    :put [:len $userList]
    :put $userList
    :put "- foreach start -"
    :foreach t in=$userList do={
        :put [:len $t]
        :put $t
        :local activeUser [/ip hotspot active find user=[/ip hotspot user get $t name]]
        :put [:len $activeUser]
        :if ([:len $activeUser] != 0) do={
            :put $activeUser
            :put ("user: " . [/ip hotspot user get $t name])
            :put ("active: " . [/ip hotspot active get $activeUser user])
        }
        :put "- continue -"
    }
    :put "- done -"
}
My results from the two code samples:
2
*1;*2
- foreach start -
2
*1
1
*a2100fa
user: user1
active: user1
- continue -
2
*2
1
*a2100fa
user: user2
active: user1
- continue -
- done -
2
*1;*2
- foreach start -
2
*1
1
*a2100fa
user: user1
active: user1
- continue -
2
*2
0
- continue -
- done -
Last edited by Deantwo on Mon Jun 13, 2016 5:01 pm, edited 1 time in total.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 4:59 pm

i got this 
[admin@MikroTik] > # Variables:
[admin@MikroTik] > :global limitedProfile "4m"
[admin@MikroTik] > # Code:
[admin@MikroTik] > /ip hotspot user {
{...     :local userList [find profile=$limitedProfile]
{...     :put [:len $userList]                         
{...     :put $userList       
{...     :put "- foreach start -"
{...     :foreach user in=$userList do={
{{...         :put [:len $user]         
{{...         :put $user       
{{...         :local activeUser [/ip hotspot active find user=[/ip hotspot user get $user name]]
{{...         :put [:len $activeUser]                                                           
{{...         :if ([:len $activeUser] != 0) do={
{{{...             :put $activeUser             
{{{...             :put ("user: " . [/ip hotspot user get $user name])
{{{...             :put ("active: " . [/ip hotspot active get $activeUser user])
{{{...         }                                                                
{{...         :put "- continue -"
{{...     }                      
{...     :put "- done -"
{... }                  
4
*10;*11;*12;*13
- foreach start -
3
*10
11
*a000001;*a0000e1;*a0000e2;*a0000e3;*a0000e7;*a0000e9;*a0000eb;*a0000ef;*a0000f3;*a0000f6;*a0000fa
user: sameer
invalid internal item number

 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 5:00 pm

Maybe try not to use variables with the same name as internal properties and variables.
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 5:03 pm

Maybe try not to use variables with the same name as internal properties and variables.
Yeah, that is my guess.
I have just never had an issue with this before.
No clue why it is acting this weird about it either.

An error message would be lovely in this case, "cannot use reserved variable name".
Last edited by Deantwo on Mon Jun 13, 2016 5:12 pm, edited 3 times in total.
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Mon Jun 13, 2016 5:06 pm

Ok, with all that nonsense settled.
Try this AYcoo:
# Checks if limited users has reached the limit, if they have then set them to be limited slow state.
# Run this script every few minutes.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
    :local trafLimit 10000
# Code:
    :local uList [find profile=$limitedProfile]
    :foreach u in=$uList do={
        :local traf ([get $u bytes-in] + [get $u bytes-out])
        :local uActive [/ip hotspot active find user=[/ip hotspot user get $u name]]
        :if ([:len $uActive] != 0) do={
            :set traf ($traf + [/ip hotspot active get $uActive bytes-in] + [/ip hotspot active get $uActive bytes-out])
        }
        :put ("User (" . [get $u name] . ") traf: " . $traf)
        :if ($traf > $trafLimit) do={
            set $u profile=$limitedSlowProfile
            :put ("User (" . [get $u name] . ") reached the traf limit")
            :if ([:len $uActive] != 0) do={
                /ip hotspot active remove $uActive
                :put ("User (" . [get $u name] . ") has been forcefully logged out")
            }
            :log warning ("User (" . [get $u name] . ") reached the traf limit")
        }
    }
}
# Reset counters of the limited users and changes back to limited non-slow profile.
# Run this script once every day.
/ip hotspot user {
# Variables:
    :local limitedProfile "Limited"
    :local limitedSlowProfile "LimitedSlow"
# Code:
    :foreach u in=[find (profile=$limitedProfile || profile=$limitedSlowProfile)] do={
        reset-counters $u
        set $u profile=$limitedProfile
        /ip hotspot active remove [/ip hotspot active find user=[/ip hotspot user get $u name]]
    }
    :log warning "All user limits has been reset"
}
I pretty much just renamed all the variables.
Should work now.

EIDT: Small edit to make the reset script work a little better.
EDIT2: Updated comment of the reset script.
Last edited by Deantwo on Tue Aug 16, 2016 10:58 am, edited 4 times in total.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Tue Jun 14, 2016 9:05 pm

perfect  thanks finally it worked 
 
aboyomna2006
just joined
Posts: 12
Joined: Mon Jun 27, 2016 4:29 am

Re: RE: Re: how to make user bytes out statistics calculate with active user

Mon Jun 27, 2016 6:05 am

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
Dears
Please i want trying this script
When the users have 2 giga(example) the scriot change it to another slow profile

Sent from my SM-N900 using Tapatalk
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: RE: Re: how to make user bytes out statistics calculate with active user

Mon Jun 27, 2016 8:05 am

I can make a script for you to change his profile to slower one after kicking him out
what u want can be done but it is not easy ..
Dears
Please i want trying this script
When the users have 2 giga(example) the scriot change it to another slow profile
The above two scripts I posted do this.
Here: http://forum.mikrotik.com/viewtopic.php ... 43#p542343

You just need to fill in the names of the two profiles, and a bandwidth limit. And then of course setup some schedulers to run the scripts at specified intervals.
 
aboyomna2006
just joined
Posts: 12
Joined: Mon Jun 27, 2016 4:29 am

Re: how to make user bytes out statistics calculate with active user to limit user download

Wed Jun 29, 2016 3:59 am

Thanks my dear
Can you make me Script. Can disable active port in dhcp-client ?

Sent from my SM-N900 using Tapatalk
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Wed Jun 29, 2016 7:40 am

Can you make me Script. Can disable active port in dhcp-client ?
Suggest you make a new thread and give more details as to what you mean.
 
aboyomna2006
just joined
Posts: 12
Joined: Mon Jun 27, 2016 4:29 am

Re: RE: Re: how to make user bytes out statistics calculate with active user to limit user download

Wed Jun 29, 2016 7:45 am

Can you make me Script. Can disable active port in dhcp-client ?
Suggest you make a new thread and give more details as to what you mean.
Ok dear i will do

Sent from my SM-N900 using Tapatalk
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Sun Aug 14, 2016 6:58 pm

Ok, with all that nonsense settled.
Try this AYcoo:

I pretty much just renamed all the variables.
Should work now.

EIDT: Small edit to make the reset script work a little better.
EDIT2: Updated comment of the reset script.
hello Deantwo i hope ur fine
i have a request
can u do the same script for pppoe ?
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Tue Aug 16, 2016 10:12 am

hello Deantwo i hope ur fine
i have a request
can u do the same script for pppoe ?
What does PPPoE have to do with Hotspot Users?
But maybe, will have to look at it when I have time.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Tue Aug 16, 2016 10:47 am

hello Deantwo i hope ur fine
i have a request
can u do the same script for pppoe ?
What does PPPoE have to do with Hotspot Users?
But maybe, will have to look at it when I have time.
i ment use the same idea with PPPoE

limit download for user ( secrets) who reah x bandwidth every day and reset -maybe do this from queues -
i don't know if it possible

the script u made is great but it has one disadvantage which is user must logout and login again everyday if only there is a solution for this
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Thu Aug 18, 2016 1:54 am

hello Deantwo i hope ur fine
i have a request
can u do the same script for pppoe ?
What does PPPoE have to do with Hotspot Users?
But maybe, will have to look at it when I have time.
ok let's start this again
can u do the same idea limit download if user reach x mb only this time change queues no need for active or user
all variables in queues

i tried this but there are mistakes
:local traf; 
/queue simple 
:for i from=1 to= 254 do=  { 
:if ([/queue simple find target-addresses=("10.0.1." . $i)] != "") do={ 
:local traf [get [find target-addresses=("10.0.1." . $i)] total-bytes] 
:if ($traf  > 7600) do= { 
set [find target-addresses=("10.0.1." . $i)] max-limit= 32000/64000 
} 
} 
}
and this
/queue simple; 
:foreach i in=[find] \
do={  \
     :local sqName [get $i name]; \
     :local sqTotalBytes [get $i total-bytes]; \

     :local sqLevel [:find $sqName "[q1]"]; \
     :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  > 8576)  do={ \
          set $i limit-at=24000/24000 max-limit=32000/32000 burst-threshold=0/0 burst-limit=0/0 burst-time=0/0; \
        }; \
     }} 

please Deantwo this is important cuz in this way user won't need to log out or in

waiting u m8
You do not have the required permissions to view the files attached to this post.
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: how to make user bytes out statistics calculate with active user to limit user download

Thu Aug 18, 2016 5:16 am

i think i got it working now i just need way to reset every day and also better way to use it like groups 4mb 8mb etc
* still problem the script change speed even if user did not reach limit
/queue simple { 

     :local uName "q1"
     :local uTotalBytes "1000"

     :local uList [find name=$uName]
     :foreach u in=$uList do={
:local traf ([get $u total-bytes])
        :if ($traf > $uTotalBytes)  do={
              set $u limit-at=24000/24000 max-limit=32000/32000 
        
     }} 

}
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: hotspot & queues user speed limit after x download scripts

Thu Aug 18, 2016 8:09 am

I have just never used simple queues, and haven't had time recently to look into it.
I am however sure that someone else has done this before, or maybe simple queues can do this with built-in features?
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: hotspot & queues user speed limit after x download scripts

Thu Aug 18, 2016 12:54 pm

:(
any one have done this can help plz?
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: hotspot & queues user speed limit after x download scripts

Thu Aug 18, 2016 1:22 pm

I have just never used simple queues, and haven't had time recently to look into it.
I am however sure that someone else has done this before, or maybe simple queues can do this with built-in features?
found this but didn't work http://wiki.mikrotik.com/wiki/Limiting_ ... ser_levels

* it is working now i was using wrong input number
:local uName "q1"
     :local uTotalBytes "1000"

     :local uList [find name=$uName]
     :foreach u in=$uList do={
:local traf ([get $u total-bytes])
        :if ($traf > $uTotalBytes)  do={
              set $u limit-at=24000/24000 max-limit=32000/32000 
        
     }} 

}
reset
/queue simple { 

     :local uName "q1"
     

     :local uList [find name=$uName]
     :foreach u in=$uList do={

              set $u limit-at=0/0 max-limit=356352/5242880
        
     } 
reset-counters-all
:log warning "$uName limits has been reset"
}
just need to do this for every client
 
User avatar
AYcoo
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 93
Joined: Thu May 19, 2016 8:44 pm

Re: hotspot & queues user speed limit after x download scripts

Sat Aug 20, 2016 2:21 pm

can any one help me get this right plz
i want to tel it if it is already the limit then don't do anything but if it is not then limit him by decreasing his speed
/queue simple { 

        :local uName "ali6m"
        :local uTotalBytes 10737418240
        :local uList [find name=$uName]
        :foreach u in=$uList do={
        :local umax [get $u max-limit] 
:if ($umax > 2097152) do={} else {
        :local traf [get $u total-bytes]
        :if ($traf > $uTotalBytes) do={

         set $u burst-limit=229376/2097152 burst-threshold=229376/2097152 burst-time=\
         5s/5s max-limit=229376/2097152 
        
     }} }

}
 
luongvancanh
just joined
Posts: 5
Joined: Mon Aug 07, 2017 5:28 am
Contact:

Re: hotspot & queues user speed limit after x download scripts

Wed Apr 03, 2019 7:19 pm

Hi everybody,
I thanks AYcoo posted the code at viewtopic.php?f=9&t=108553&p=724807#p540241 . It worked well.
However, I would like test tx-rate+rx rate of active users. If tx-rate+rx rate >10m, this user will put slow profile.
What code can I do that?
Please help me! Thanks a lot for any guide.
Thanks, Thanks, Thanks......

Who is online

Users browsing this forum: No registered users and 13 guests