1. Go to this page and download the library: Download joserf/mikrotik-php-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
r_reporting(E_ALL);
use \RouterOS\Config;
use \RouterOS\Client;
use \RouterOS\Query;
// Create config object with parameters
$config =
(new Config())
->set('host', '192.168.*.*')
->set('user', 'LOGIN')
->set('pass', 'SENHA');
// Initiate client with config object
$client = new Client($config);
// Build query (Get resources in RouterOS)
$query = new Query("/system/resource/print");
// Send query to RouterOS
$request = $client->query($query);
// Read answer from RouterOS
$response = $client->read();
// Print result in json format
print_r(json_encode($response, JSON_PRETTY_PRINT));
// show only rx-bits-per-second
print_r($out [0]["rx-bits-per-second"]);
// Build query (Get users active in RouterOS)
$query = new Query("/ip/hotspot/active/print");
// Count total user active in RouterOS
print_r(count($response));
// Build query (Get users active in RouterOS)
$query = new Query("/ip/hotspot/active/print");
// Print result in JSON format
print_r(json_encode($response, JSON_PRETTY_PRINT));
// Build query (Get resources in RouterOS)
$query = new Query("/system/resource/print");
// Show uptime active in RouterOS
echo 'Uptime: ' . json_encode($response[0]['uptime']);
shell
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.