Automatic Hotspot Binding

The login script below works like a champ. However, it creates a binding for every “active” user instead of the single user logging in.

:foreach users in=[/ip hotspot active find] do={
:local date [ /system clock get date ];
:local ip [/ip hotspot active get $users address];
:local mac [/ip hotspot active get $users mac-address];
:local username [/ip hotspot active get $users user];
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;
}

I simply want a user to login with a special login/password that will automatically get a binding. The script above creates a binding for everyone who is active, not just the single user.

Any ideas?

Redefine the script as an “on-login” script for the user’s profile (if it’s not already one), and use the $user variable within that script to get the username that logged on.

i.e.
:local date [ /system clock get date ];
:local ip [/ip hotspot active get $user address];
:local mac [/ip hotspot active get $user mac-address];
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;

Excuse my ignorance. I’m not a programmer. The code I listed above is part of the “on-login script”. I tried the code you provided and it failed to create a binding. Can you provide the entire script needed for this?

FYI, I currently have only two users configured for hotspot. One user is “hotspot” with default profile. The other user is “hotspot” with a separate profile which included the log-in script.

Thank you for your help.

That should be all of it.

Assuming your extra user profile is called “profile1”, all you need to do to set this script should be to execute the following one time from terminal:
/ip hotspot user profile set “profile1” on-login=":local date [ /system clock get date ];\n:local ip [/ip hotspot active get $user address];\n:local mac [/ip hotspot active get $user mac-address];\n/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;\n"See this page from the manual. BTW, what RouterOS version are you using?

Cannot get the script to work. It does authenticate the user, however the binding doesn’t get created. Log shows “bypass (10.5.50.145): logged out: host removed: administrator request”

RB750 SW 6.5

Hi,

How do I run these scripts I’ve been trying all morning with no joy running v6.15

Here is what worked for me, just copy and past into user profile, script - on login

 :local date [ /system clock get date ];
 if ($user = "vip" ) do={ :local mac [/ip hotspot active get [find where user=$user] mac-address]
 :local host [/ip dhcp-server lease get [find where mac-address=$mac] host-name]
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment="$host - $date";
 }

OK so it turns out this doesn’t work if there is more than 1 user logged in, anyone know what I need to add to make it go through all users and only add usernames with vip?