Community discussions

MikroTik App
 
loverboy
just joined
Topic Author
Posts: 6
Joined: Tue Jun 06, 2017 5:36 am

get active user hotspot by php api hlep me

Sun Jul 09, 2017 1:50 am

haloo evry body
i need show user and active users for hotspot
iam try by this code but not work
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';




 $util = new RouterOS\Util($client = new RouterOS\Client('8.8.8.2', 'admin', ''));
 $printRequest = new RouterOS\Request('/ip/hotspot/active/print');
echo $printRequest
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: get active user hotspot by php api hlep me

Sun Jul 09, 2017 3:50 am

Either the Request must be sent using Client, or you could use Util's methods. You have everything ready, just haven't actually asked the router.

Using Util f.e.
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';




 $util = new RouterOS\Util($client = new RouterOS\Client('8.8.8.2', 'admin', ''));
 $activeUsers = $util->setMenu('/ip/hotspot/active')->getAll();
 
 //Display the usernames of each active user
 foreach ($activeUsers as $user) {
 echo $user('name'), '\n';
 }
 
loverboy
just joined
Topic Author
Posts: 6
Joined: Tue Jun 06, 2017 5:36 am

Re: get active user hotspot by php api hlep me

Sun Jul 09, 2017 9:18 am

Either the Request must be sent using Client, or you could use Util's methods. You have everything ready, just haven't actually asked the router.

Using Util f.e.
use PEAR2\Net\RouterOS;
require_once 'system/autoload/PEAR2/Autoload.php';




 $util = new RouterOS\Util($client = new RouterOS\Client('8.8.8.2', 'admin', ''));
 $activeUsers = $util->setMenu('/ip/hotspot/active')->getAll();
 
 //Display the usernames of each active user
 foreach ($activeUsers as $user) {
 echo $user('name'), '\n';
 }

thank u for help me
this code is good but
user name not print
بدون عنوان.png
You do not have the required permissions to view the files attached to this post.
 
loverboy
just joined
Topic Author
Posts: 6
Joined: Tue Jun 06, 2017 5:36 am

Re: get active user hotspot by php api hlep me

Sun Jul 09, 2017 11:21 am

iam edit code
now it's work
but i cant get hotspot user
ineed get user limit-bytes-total

$activeUsers = $util->setMenu('/ip/hotspot/active')->getAll();
 
 //Display the usernames of each active user
foreach ($activeUsers as $user) {
 echo $user('user');
 
 $userlimit = $util->setMenu('/ip/hotspot/user/')->getAll();
 foreach ($userlimit as $xxx){
 echo $xxx('limit-bytes-total');}
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: get active user hotspot by php api hlep me

Sun Jul 09, 2017 6:56 pm

Oh, right... "user", not "name". I keep forgetting which menu has which property name... And yeah, I used single quotes when I should've used double (which would've created a few new lines in the output), sorry.

The "/ip hotspot user" menu is for all users (and that's where the property is called "name"), while "/ip hotspot active" is for all "active" (as in, "logged in") users. If you're trying to read data from there, that's the only menu you should be reading out of. The limit-bytes-out should be readable from there if you add the "stats" argument, i.e.
$activeUsers = $util->setMenu('/ip/hotspot/active')->getAll(array('stats'));
 
 //Display the username and limit-bytes-total of each active user
foreach ($activeUsers as $user) {
 echo $user('user') . ' - ' . $user('limit-bytes-total') . ";\n";
}
(or if that doesn't work, try to replace "stats" with "detail")
 
User avatar
kvee
newbie
Posts: 38
Joined: Mon Feb 13, 2023 7:59 pm

Re: get active user hotspot by php api hlep me

Wed May 10, 2023 1:17 pm

The /ip/hotspot/active is good but can retrieve all active hotspot users included duplicate users who online with more than one devices.

To find only active users without duplicated, use `:put [find active-sessions]`.

With Node package aluisiora/node-routeros, use
conn.write('/tool/user-manager/user/print', ['?active-sessions'])

Who is online

Users browsing this forum: No registered users and 78 guests