Community discussions

MikroTik App
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 11:34 am

Hi guys... How can I identify if the RouterOS/User-Manager is up/running or not?... using Pear2 RouterOS API...
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 12:10 pm

Checking RouterOS itself is as simple as making a connection attempt.

To check if User Manager is accepting connections, once you make a connection with the API, you can do
$isRadiusRunning = 'true' === $util->setMenu('/radius incoming')->get(null, 'accept');
if ($isRadiusRunning) {
//RADIUS server (i.e. User Manager) is working
} else {
//RADIUS server (i.e. User Manager) is not working
} 
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 12:19 pm

wow... that was fantastic.. thanks (y) :D
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 12:19 pm

one more question...

I got this code somewhere around the forum while searching for testing connectivity...

it worked and showed the connection error time out... but the problem was the timeout was 1 minute long...

how can i reduce it to 10 seconds?
try 
    {
      	$client = new RouterOS\Client( "xxx.xxx.xxx.xxx", "username", "password");
    } 
    catch (RouterOS\DataFlowException $e) 
    {//In this try block's case, invalid credentials is the only possibility
       echo $e->getMessage();
    } 
    catch (RouterOS\SocketException $e) 
    {
        //In this try block's case, connection failure is one of two possibilities,
        //the other being that you're connecting to a different kind of service (e.g. if you have an HTTP server at that port)
        $previous = $e->getPrevious();
        if ($previous instanceof \Exception) 
        {
            echo = "{$previous->getSocketErrorNumber()}: {$previous->getSocketErrorMessage()}" . "\n";
        } 
        else 
        {
            echo = $e->getMessage();
        }
    }
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 12:49 pm

It's the 5th constructor argument, in seconds. F.e.
new RouterOS\Client( "xxx.xxx.xxx.xxx", "username", "password", null, false, 10);
will set the timeout to 10 seconds.

Alternatively, you can set the php.ini directive default_socket_timeout. In the absence of a timeout in the constructor, the value of that directive is what's honored.
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 12:51 pm

ohh I didn't know... thanks once again :D
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 1:05 pm

Checking RouterOS itself is as simple as making a connection attempt.

To check if User Manager is accepting connections, once you make a connection with the API, you can do
$isRadiusRunning = 'true' === $util->setMenu('/radius incoming')->get(null, 'accept');
if ($isRadiusRunning) {
//RADIUS server (i.e. User Manager) is working
} else {
//RADIUS server (i.e. User Manager) is not working
}
I forgot to ask... is this the same as radtest from this guide https://wiki.freeradius.org/guide/Radtest ?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: how to know if routeros/usermanager is running or not

Thu Apr 06, 2017 1:14 pm

No. The code above tests if the RADIUS server is running and accepting connections. The test you're linking to instead tests how the server would respond to a particular query.

If you want to test how the RADIUS server would respond to a query, you need to use a RADIUS client, like this PECL package for example or this library.
 
termers
just joined
Topic Author
Posts: 19
Joined: Fri Jan 20, 2017 2:46 am

Re: how to know if routeros/usermanager is running or not

Fri Apr 07, 2017 5:24 am

Thanks... I'll study it well :)

Who is online

Users browsing this forum: own3r1138 and 64 guests