Community discussions

MikroTik App
 
tarzq28
just joined
Topic Author
Posts: 10
Joined: Wed May 17, 2017 2:34 pm
Location: Indonesia
Contact:

[ASK] Script for user based on data usage

Tue Dec 17, 2019 11:06 am

Hai guys, I want to make policy in my network. So let say we give user 75Gb of quota and we want to make sure if user reach 50% of their internet data usage the speed will drop to 80% of their current max limit and 75% if they reach 80% internet data usage. I know the idea behind these scenario but I'm difficult to implement it via mikrotik scripting since I'm not play so much with script. Is anybody know how to write script for this scenario? Or share it here if you already know it.

Sorry for my bad english.

Sent from my Redmi 5 using Tapatalk

 
sopyan0807
newbie
Posts: 39
Joined: Wed Jan 22, 2020 5:21 pm
Location: Indonesia
Contact:

Re: [ASK] Script for user based on data usage

Sat Jan 25, 2020 11:22 am

create three user profiles according to speed, then run this script using the scheduler
:foreach i in=[/ip hotspot active find]  do={
/ip hotspot active remove $i
}
/ip hotspot user {
    :local limitedProfile "5m"
    :local limitedSlowProfile "fup1"
    :local trafLimit 1073741824

    :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")
        }
    }
}
 /ip hotspot user {
    :local limitedProfile "fup1"
    :local limitedSlowProfile "fup2"
    :local trafLimit 1610612736

    :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")
        }
    }
}

Image

viewtopic.php?f=9&t=108553&p=724807#p540241
 
jcbhnz
just joined
Posts: 19
Joined: Tue Dec 14, 2021 1:32 pm

Re: [ASK] Script for user based on data usage

Sat Feb 04, 2023 9:02 am

Has anyone had any success using the above script?
Have tried on two routers, one RB5009UG+S+ running v7.7 and the other a RB750Gr3 running v6.49.7, without success.
Is it compatible with those versions of RouterOS?

Thanks
jcbhnz

Who is online

Users browsing this forum: No registered users and 13 guests