I’m starting to use mikrotik, I’m really enjoying the control power that RB allows and I’ve been researching about the range of possibilities that exist for a hotspot configuration and I’m having a question regarding the mikrotik API.
How can I get the ip and mac information of the device connected to mikrotik and whether or not it is logged in to the hotspot in the same way that the login page or status sends via POST.
I would like to use via API because I believe it would be more efficient than making several requests to the mikrotik login page to obtain this information.
That page checks the username of the user that opened the page as part of the process, but instead of changing the password for that user, you can just further query the router for information related to the user.
on-login: List of available variables:
$user
$username (alternative var name for $user)
$address
$"mac-address"
$interface
on-logout: List of available variables:
$user
$username (alternative var name for $user)
$address
$"mac-address"
$interface
$cause
Starting with v6.34rc11 some additional variables are available:
$uptime-secs - final session time in seconds
$bytes-in - bytes uploaded
$bytes-out - bytes downloaded
$bytes-total - bytes up + bytes down
$packets-in - packets uploaded
$packets-out - packets downloaded
$packets-total - packets up + packets down
The very next example uses the hotspot cookie instead of $_SERVER[‘REMOTE_ADDR’], but as the entire section clarifies, you need to setup the router and server in a particular way to enable the server to read cookies set by the router.
Once you have the user, you can use it to filter other hotspot menus for it, such as finding information about them or the profile they are associated with. If the information you want is in the “cookie” menu, you can also get it as part of the same request you get the username from, e.g.