Community discussions

MikroTik App
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Pear2 - API

Wed Oct 07, 2020 1:27 am

all i want is simple command /print log or /print arp or /print interface
how can i do it in php?
i saw this code but i don't know did i do it correctly
<?php

use PEAR2\Net\RouterOS;
// require_once 'pear2\src\PEAR2\Autoload.php';
require_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';

//IP MIKROTIK //Usuario //Password
$client = new RouterOS\Client('ip', 'user', 'pass'); //Connect a Mikrotik

// Tabla
echo "<table align='center' border='1' bordercolor='black'><form action='' method='POST'>";
echo "<tr bgcolor='#D8D8D8'><td align=left size=3>Number</td><td align=left size=3>MAC-Address</td><td size=3>Name</td><td align=left size=3>IP</td><td align=left size=3>Address</td></tr>";

//Actualizar pagina
echo "<meta http-equiv='refresh' content='2'>";


$interfaces = $client->sendSync(new RouterOS\Request('/interface/ethernet/print'));
$arps = $client->sendSync(new RouterOS\Request('/ip/arp/print'));


if ($interfaces['name']==$arps['name']) {
foreach (array_combine($interfaces, $arps) as $interface => $arp) {
if ($interface->getType() === RouterOS\Response::TYPE_DATA OR $ethernet->getType() === RouterOS\Response::TYPE_DATA ) {
$id = $interface('.id');
$id2 = $arp ('.id');
echo "<tr>";
echo "<td>". $interface('name') ."</td>";
echo "<td>". $interface('type'). "</td>";
echo "<td>". $interface('MAC-Address'). "</td>";
echo "<td>". $ppp('') ."</td>";
echo "<td><input type='submit' value='Reiniciar' name='Reiniciar' /></td></tr>";
}
}
}

echo "</form></table>"

?>
 
akram
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 88
Joined: Wed Aug 10, 2005 4:58 pm

Re: Pear2 - API  [SOLVED]

Wed Oct 07, 2020 11:14 am

at last i found the code for arp print

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';


define('TYPE_DATA', '!re');
define('TYPE_FINAL', '!done');
define('TYPE_ERROR', '!trap');
define('TYPE_FATAL', '!fatal');



try {
$client = new RouterOS\Client('put ur ip', 'put ur user', 'put ur password', 8728);

echo 'Connected!';



$responses = $client->sendSync(new RouterOS\Request('/ip/arp/print'));
foreach ($responses as $response) {

if ($response->getType() != '!done') {
echo "<tr>";
echo 'IP: ', $response->getProperty('address'),
' MAC: ', $response->getProperty('mac-address'),

"\n";
}
}
} catch (Exception $e) {
echo '<pre>';
var_dump($e);
echo '</pre>';
}
You do not have the required permissions to view the files attached to this post.