Community discussions

MikroTik App
 
macardenas
just joined
Topic Author
Posts: 1
Joined: Mon Mar 06, 2023 6:55 pm

API Authentication RouterOS 6.49 (stable)

Mon Mar 06, 2023 7:05 pm

Good morning dear,

I have a question. I am trying to connect to my Mikrotik via API but authentication has not been possible. In my Mikrotik log, the login failed. I'll leave the code snippet I'm using:
<?php
use PEAR2\Net\RouterOS;

//require_once 'PEAR2/Autoload.php';
require_once 'PEAR2_Net_RouterOS-1.0.0b6.phar';
try {
    $client = new RouterOS\Client('192.168.1.100', 'admin', 'Thomas');
} catch (Exception $e) {
    die('Unable to connect to the router.');
}

$addRequest = new RouterOS\Request('/ip/arp/add');

$addRequest->setArgument('address', '192.168.88.100');
$addRequest->setArgument('mac-address', '00:00:00:00:00:01');
if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
    die("Error when creating ARP entry for '192.168.0.100'");
}

$addRequest->setArgument('address', '192.168.88.101');
$addRequest->setArgument('mac-address', '00:00:00:00:00:02');
if ($client->sendSync($addRequest)->getType() !== Response::TYPE_FINAL) {
    die("Error when creating ARP entry for '192.168.0.101'");
}

echo 'OK';
It tells me that the username and password are incorrect (which I already checked and I have my credentials and permissions well established). From what I read in this version I change the way to authenticate. If anyone can help me with this matter I would appreciate it.

Thanks in advance

Who is online

Users browsing this forum: No registered users and 20 guests