Mikrotik API - Show hotspot customer information

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.

Check out the forgotten password example for an example of this very thing.

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.

ref: https://wiki.mikrotik.com/wiki/Manual:IP/Hotspot/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

With the boen_robot hint I checked the code but found only “$ _SERVER [‘REMOTE_ADDR’]” which returns the ip address through php.

I would have some way to get this information reliably through RB.

appreciate

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.

    $printRequest = new RouterOS\Request(
        '/ip hotspot cookie print .proplist="user,mac-address"',
        RouterOS\Query::where('.id', '*' . strtoupper(base_convert($_COOKIE['loginID'], 10, 16)))
    );
    $hotspotUser = $client->sendSync($printRequest);
    $hotspotUsername = $hotspotUser->getProperty('user');
    $hotspotMacAddress = $hotspotUser->getProperty('mac-address');

otherwise, from the relevant menu, e.g.

    $activePrintRequest = new RouterOS\Request(
        '/ip hotspot active print .proplist="uptime,address"',
        RouterOS\Query::where('user', $hotspotUsername)
    );
    $activeHotspotUser = $client->sendSync($activePrintRequest);
    $hotspotUptime = $activeHotspotUser->getProperty('uptime');
    $hotspotAddress = $activeHotspotUser->getProperty('address');