phpmikrotikrouter-os

how to earn online user with mikrotik pear2 api?


i used pear2 api for disconnect user from mikrotik. with

$printRequest = new RouterOS\Request('/ip/hotspot/active/print');
        $printRequest->setArgument('.proplist', '.id,mac-address');

        $printRequest->setQuery(RouterOS\Query::where('user', $username)->andWhere('mac-address',$macAddress));

        $id = $this->client->sendSync($printRequest)->getArgument('.id');


        $removeRequest = new RouterOS\Request('/ip/hotspot/active/remove');
        $removeRequest->setArgument('numbers', $id);
        $this->client->sendSync($removeRequest);

now i want get all online user with this api. please guide me.


Solution

  •  $printRequest = new RouterOS\Request('/ip/hotspot/active/print');
     $printRequest->setArgument('.proplist', 'address,user,.id');
    
     $id = $this->client->sendSync($printRequest)->getAllOfType(RouterOS\Response::TYPE_DATA);
     foreach ($id as $response) {
          echo $response('.id'), '--', $response('user'), '--', $response('address'), "\n";
     }