PHP code example of ums / mikrotik

1. Go to this page and download the library: Download ums/mikrotik 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/ */

    

ums / mikrotik example snippets



use MikrotikSdk\MikrotikSdk;

$mikrotik = new MikrotikSdk;

// Connect to Mikrotik
$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');
if ($connect) {
    echo 'Connected';
} else {
    echo 'Not Connected';
}


$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');

$disconnect = $mikrotik->disconnect();

$result = $mikrotik->executeCommand('/interface/print');

$response = $mikrotik->sendCommand('/ip/address/print', ['?interface' => 'ether1']);

$parsedData = $mikrotik->parseResponse($response);

use MikrotikSdk\MikrotikSdk;

$mikrotik = new MikrotikSdk;

// Connect to Mikrotik
$connect = $mikrotik->connect('192.168.88.1', 'admin', 'password');
if ($connect) {
    // Execute a command
    $response = $mikrotik->sendCommand('/ip/address/print', ['?interface' => 'ether1']);
    
    // Parse and display the response
    $parsedData = $mikrotik->parseResponse($response);
    print_r($parsedData);

    // Disconnect from Mikrotik
    $mikrotik->disconnect();
} else {
    echo 'Not Connected';
}