Community discussions

just joined
Topic Author
Posts: 7
Joined: Fri Apr 05, 2019 4:55 pm

hotspot - make lease static after login

Sat Apr 06, 2019 12:13 am


I'm trying to setup an "advenced" hotspot on the RouterOS. Basic configuration covered by official documentation works
like a charm but the goal is to create the hotspot for a dormitory with additional rules:

1. After first login, the Mac Address should be bound to the user

2. The static lease should be created on the DHCP to bind Mac Address to the IP - we want the user to use "static" address assigned from dhcp and
we don't want this address to be changed during the accommodation.

I came out with hotspot user profile on login script:
:local u [/ip hotspot user find name=$username ];
:if ([:len $u] > 0) do {
    :if ([:len [/ip hotspot user get $u "mac-address"]] < 1) do {
        # bind mac address to the user
        /ip hotspot user set $u mac-address=$"mac-address";
        # convert the dynamic lease into the static lease
        :local lea [/ip dhcp-server lease find mac-address=$"mac-address"];
        log info message=$lea;
        /ip dhcp-server lease make-static $lea;
the first part works (binding mac to user) but unfortunatelly, for some reason, after each login,
all the leases are coverted to the static leases. Following line:
/ip dhcp-server lease find mac-address=$"mac-address"
returns array containing ALL leases and should return only one lease which corresponds to the mac address.
I can see it in the log: "*2;*3;*4"

funny thing is, when I try to execute command like:
:put [/ip dhcp-server lease find mac-address=08:00:27:8B:C4:CD]
outside of the script, it displays only ONE element (as expected).

What am'i missing? Is it bug or my mistake?

Best regards,
You do not have the required permissions to view the files attached to this post.
User avatar
Posts: 391
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany

Re: hotspot - make lease static after login  [SOLVED]

Tue Apr 16, 2019 12:51 pm

Well, an odd behavior in RouterOS... Mikrotik support says "that's how scripting works in RouterOS".

You can not use same variable name and option name. I switched to use variable names in CamelCase. Just replace $"mac-address" with $MacAddress.

Read my detailed analysis and solution here:
global: variable names are CamelCase
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
just joined
Topic Author
Posts: 7
Joined: Fri Apr 05, 2019 4:55 pm

Re: hotspot - make lease static after login

Mon Jun 17, 2019 11:00 pm

Hello, support gave me similar answer. As you noticed very strange language "feature".

Best regards,

Who is online

Users browsing this forum: No registered users and 7 guests