Add a data limit to trial hotspot users

From MikroTik Wiki
Jump to: navigation, search


The following script allows you to assign a data limit to trial hotspot users and

a) have them kicked offline upon reaching this limit

b) create a temporary local user to stop them from logging back in again

This is a feature which is not available via the current hotspot settings, so I decided to script it into existence. Enjoy!


Script to check users for those over the limit:

Make a scheduler entry to run this every X minutes, I'd recommend every 5-10 minutes.

#Download limit in MB
:local downquotamb "50"

### Do not modify anything below this line ###
:local downquota [$downquotamb * 1000]
:local counter
:local datadown
:local username
:local macaddress
:foreach counter in=[/ip hotspot active find ] do={
:set datadown [/ip hotspot active get $counter bytes-out]
:if ($datadown>$downquota) do={
:set username [/ip hotspot active get $counter user]
:set macaddress [/ip hotspot active get $counter mac-address]
/ip hotspot user remove [/ip hotspot user find where name=$username]
/ip hotspot user add name=$username limit-bytes-out=$downquota mac-address=$macaddress
/ip hotspot active remove $counter
:log info "Logged out $username - Reached download quota"

Script to clear all manually created user accounts; this can be done hourly, daily or weekly depending on your requirements.

:foreach counter in=[/ip hotspot user find ] do={/ip hotspot user remove \$counter}


You can modify how often you want each of the scripts to be run depending on your bandwidth requirements however you will need to clear the manually created user accounts if you wish for the user to be able to log back in again.