Esempio n. 1
0
 * Example script demonstrating the basic functions of Lib_RouterOS.
 * This example connects to the router, logs in, and issues a command
 * to retrieve some select system information.
 *
 */
// define required values
$router = '192.168.88.1:8728';
$username = '******';
$password = '';
// basic informational command to send
$command = '/system/resource/print';
$args = array('.proplist' => 'version,cpu,cpu-frequency,cpu-load,uptime');
// begin script
require_once 'RouterOS.php';
$mikrotik = new Lib_RouterOS();
$mikrotik->setDebug(true);
try {
    // establish connection to router; throws exception if connection fails
    $mikrotik->connect($router);
    // send login sequence; throws exception on invalid username/password
    $mikrotik->login($username, $password);
    // encodes and send command to router; throws exception if connection lost
    $mikrotik->send($command, $args);
    // read response to command; throws exception if command was invalid (!trap,
    // !fatal etc), connection terminated, or recv'd unexpected data
    $response = $mikrotik->read();
    // show the structure of the parsed response
    print_r($response);
} catch (Exception $ex) {
    echo "Caught exception from router: " . $ex->getMessage() . "\n";
}
Esempio n. 2
0
 } else {
     $action = $sentence[0];
     echo "{$router_identity} {$action}>";
 }
 // read a line of input
 $input = trim(fgets(STDIN));
 if (strlen($input) > 0 && $input[0] != '/') {
     // if there is input that does not begin with "/"
     if ($input == 'quit' || $input == 'exit' || $input == chr(4)) {
         // check for one or more ways to quit
         $input = '/quit';
     } else {
         if ($input == 'setdebug') {
             // toggle debug output
             $dbg = $mt->getDebug();
             $mt->setDebug(!$dbg);
             if ($dbg) {
                 echo "Debugging disabled\n";
             } else {
                 echo "Debugging enabled\n";
             }
             continue;
         }
     }
 }
 if ($input == '' || $input == '/quit' || substr($input, -1) == ';') {
     // if input was empty, or quit - send sentence
     if ($input == '/quit') {
         $sentence = array($input);
     }
     if (substr($input, -1) == ';') {