PHP API send disconnection random PPTP active users

Good Morning Friends,

i have multiple mikrotik routers as RRAS, i want to send disconnection through php API.

is there any way to send random disconnection for users to RAS server instead of individual user through mikrotik .id

You want to disconnect a random user?!?

That’s an odd request, but OK…

Get a list of all active users, get their count, and use mt_rand(0, $usersCount - 1) to get a random number between 0 and the number of users. Lookup the generated number in the list of users, and disconnect the user corresponding to that number.

When you say RRAS though… That sounds overly generic… In what fashion to users log in? Hotspot? PPPoE?

If it’s with hotspot for example, you can do the following (using the PHP client from my signature):

<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

$util = new RouterOS\Util($client = new RouterOS\Client('192.168.88.1', 'admin', 'password'));

$util->setMenu('/ip hotspot active');

$userIds = $util->getAll(array('.proplist' => '.id'));
$userIdsCount = count($userIds);
if ($userIdsCount > 0) {
    $idToDisconnect = $userIds[mt_rand(0, $userIdsCount - 1)]->getProperty('.id');
    $util->remove($idToDisconnect);
}

The procedure is analogous for other menus, except that the line

$util->setMenu('/ip hotspot active');

needs to instead point at whatever other menu active users are listed in.

Thanx bro