1. Go to this page and download the library: Download ocolin/routeros 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/ */
// Get interfaces of type equal to ether
$command = new Command( '/interface/print' )
->query( key: 'type', value: 'ether', operator: '=' );
// Get interfaces with any link-downs
$command = new Command( '/interface/print' )
->query( key: 'link-downs', value: 0, operator: '>' );
// Get interfaces of type equal to ether
$command = new Command( '/interface/print' )
->query( key: 'type' )->equals( 'ether' );
// Get interfaces with any no link-downs
$command = new Command( '/interface/print' )
->query( key: 'link-downs' )->lessThan( 1 );
// Get interfaces with link-downs
$command = new Command( '/interface/print' )
->query( key: 'link-downs' )->greaterThan( 0 );
// Get interfaces with link-downs property
$command = new Command( '/interface/print' )
->query( key: 'link-downs' )->exists();
// Get interfaces without link-downs property
$command = new Command( '/interface/print' )
->query( key: 'link-downs' )->notExists();
// Get interfaces of type equal to ether AND has link-downs
$command = new Command( '/interface/print' )
->query( key: 'type' )->equals( 'ether' )
->query( key: 'link-downs' )->greaterThan( 0 )
->and();
// Get interfaces of type equal to ether OR has link-downs
$command = new Command( '/interface/print' )
->query( key: 'type' )->equals( 'ether' )
->query( key: 'link-downs' )->greaterThan( 0 )
->or();
// Get interfaces of type not a vlan
$command = new Command( '/interface/print' )
->query( key: 'type' )->equals( 'vlan' )
->not();
$command = new Command( '/interface/print' )->proplist(['name', 'type']);
$command = new Command( '/interface/print' )->tag( 123 );
$command = new Command( '/interface/print' )->tag( 'abc' );
// Get interfaces without link-downs property
$command = new Command( '/interface/print' )
->where( key: 'link-downs' )->notExists();
foreach( $client->stream( '/interface/listen' ) as $update ) {
echo $update['name'] . ' changed state' . PHP_EOL;
// Stop listening after first update
if( $someCondition ) {
break;
}
}
$client = new Client([
'host' => '192.168.88.1',
'username' => 'admin',
'password' => 'secret',
'ssl' => true,
'sslVerify' => false // set to true if using a trusted certificate
]);
use Ocolin\RouterOS\Client;
class NetworkController extends Controller
{
public function __construct( private Client $client ) {}
public function interfaces() : array
{
return $this->client->query( '/interface/print' );
}
}