0% found this document useful (0 votes)
46 views1 page

MikroTik Hotspot User Management Script

The document contains scripts to log a user on to a hotspot, assign them an IP address, start a scheduler task, and log them off by removing the IP assignment and queue.

Uploaded by

Anto Hartanto
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views1 page

MikroTik Hotspot User Management Script

The document contains scripts to log a user on to a hotspot, assign them an IP address, start a scheduler task, and log them off by removing the IP assignment and queue.

Uploaded by

Anto Hartanto
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

logon:

:local a $user
:local m [/ip hotspot active get [find user=$a] mac-address]
:local b [/ip hotspot active get [find user=$a] address]
:log info message=("Prueba: ;$a; ;$m; ;$b;");
:local date [/system clock get date];
:local time [/system clock get time];
:log info "";
{
:if ( [ /ip hotspot user get $user comment ] = "" ) do={
[ /ip hotspot user set $user comment=$user]
}
}
/system script add name=$user policy=read,write source="/ip hotspot ip-binding
remove [find comment=$user]\r\nip dhcp-server lease remove [find
comment=$user]\r\n/queue simple remove [/queue simple find name=$user]\r\nsystem
scheduler remove [/system scheduler find name=$user]\r\nsystem script remove
[/system script find name=$user]"
system scheduler add name=$user start-time="$time" interval=10s policy=read,write
on-event=$user
/ip hotspot ip-binding add type=bypassed mac-address=$m address=$b comment=$a

:local a $user
:local b [/ip hotspot ip-binding get [find comment=$a] address]
:local m [/ip hotspot ip-binding get [find comment=$a] mac-address]
/ip dhcp-server lease add address=$b mac-address=$m disabled=no comment=$a;

LogOut:
:local a $user
:local b [/ip hotspot ip-binding get [find comment=$a] address]
/queue simple add name="$a" target="$b" max-limit=2M/2M
/ip hotspot user remove [find comment=$a]

Common questions

Powered by AI

A DHCP lease entry is created when it is verified that the user is connected. The script commands `/ip dhcp-server lease add` with associated variables for IP and MAC address when it detects the user's activity via MAC address and IP being actively retrieved, ensuring resource allocation is only for active users .

The script checks if the user's comment field is empty and assigns the username as the comment if it's missing. This is done with the conditional statement: `:if ( [ /ip hotspot user get $user comment ] = "" ) do={ [ /ip hotspot user set $user comment=$user] }`. This ensures that each DHCP lease can be tracked back to the corresponding user through their username .

The script logs user activities by storing messages that include the username, MAC address, and IP address. This is performed using the `:log info message=` command. Logging these details is critical for monitoring user behavior, diagnosing network issues, and maintaining security by providing an audit trail of network activity .

Upon logout, the script removes any existing configurations associated with the user such as IP binding, DHCP server lease, simple queue entries, scheduler events, and script entries. This ensures that any allocated resources or limits are released, using commands like `/ip hotspot ip-binding remove`, `ip dhcp-server lease remove`, and `/queue simple remove` .

The script maintains network performance limitations by using simple queues to restrict bandwidth. It adds an entry for each user with a max limit of 2M/2M, implying that each user can use up to 2 Mbps for both upload and download, as indicated in `/queue simple add name="$a" target="$b" max-limit=2M/2M` .

The scheduler is used to periodically execute the user-specific script to ensure any configurations related to a user are reset or updated at a defined interval. Its timing is configured through the `system scheduler add` command, which sets a recurrent start-time and specifies policies to control execution rights (read, write), and the event callback function (`on-event=$user`).

Removing user-related scripts and records after logout stops unnecessary consumption of resources like IP addresses, queue slots, and processing time on the network. By clearing these records, it minimizes wasted resources and ensures that new users can be readily accommodated, optimizing the network's resource allocation .

The 'bypassed' IP binding type allows a user to bypass the Hotspot login process after their initial authentication. This is important for improving network efficiency and user experience, as it means the script configures the device to automatically revert to a state where they have direct access to network resources without repeated authentication .

The system script adds a user-specific script that automates the removal of user-specific configurations such as IP bindings, DHCP leases, and queue limits. It allows automatic management of resources by deleting these configurations after a fixed interval or upon certain conditions being met, thereby maintaining efficient use of network resources and ensuring a clean state when users log out .

The script strategically uses local variables, such as `:local a $user`, to store and reference user-specific information such as usernames, MAC addresses, and IP addresses. This use of variables streamlines the script's operations by enabling straightforward updates and retrievals of user-specific data across different configurations in a cohesive manner .

You might also like