Wallogit.com
2017 © Pedro Peláez
Router Mikrotik API
Client API for RouterOS/Mikrotik, (*1)
Via composer:, (*2)
composer require ojisatriani/mikrotikapi
Manual composer.json in require section:, (*3)
"require": {
"ojisatriani/mikrotikapi": "dev-master", // <- this line
}
$php
use OjiSatriani\MikrotikApi\Mikroji;
$router = Mikroji::connect('192.168.3.1','user-api','user-api');
echo $router->ram() .'<br />'; // 1652.2
echo $router->hdd() .'<br />'; // 915.8
echo $router->cpu() .'<br />'; // 0
echo $router->rx('ether1') .'<br />'; // 1.85Kb/Mb/Gb/Tb
echo $router->tx('ether1') .'<br />'; // 47.7Kb/Mb/Gb/Tb
echo $router->rxInMb('ether1') .'<br />'; // 1.85 (view chart or graph)
echo $router->txInMb('ether1') .'<br />'; // 47.70 (view chart or graph)
echo json_encode($router->getInterface()) .'<br />'; // {"ether1":"ether1","ether2:ether2","ether3:ether3"}
echo $router->command('log/print'); // return array(), (*4)
Mikrotik Wiki page at http://wiki.mikrotik.com/wiki/API_PHP_class, (*5)
https://github.com/BenMenking/routeros-api, (*6)
RouterOS Winbox, (*7)
Go to IP -> Services and enable api service., (*8)
Go to System -> Users, tab Groups. Create new group with permissions: api, read, write., (*9)
Then after group created go to tab Users and create new. Associate this user with group previously created., (*10)
Done., (*11)