-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.php
45 lines (33 loc) · 1.25 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* 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 = 'admin';
$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";
}