Hello, my problem is as follows, I am trying to make a web application using the Mikrotik API which must by clicking on a button on the page renew the IP of the interface that I sent, I have managed to connect to the team from the API since I open the window of the logs and it shows me that it is logging well, but when I try to send the command it does not do anything. I am putting the command in the following way.
Hello Mr. Ochaconm, thank you very much for your prompt response, I appreciate your help, but I still have some doubts to clarify, in the example that put me what should I put in the “? criteria1” => ‘criteria_value1’? I need is simple, in my team I have several virtual interfaces configured and I need to be able to make a release to a specific interface, how do you think that would be the correct way to do it?
this would be an example of my code
<?php require_once('api_mt_include2.php'); ?>
<?php
$ipRouteros="192.168.17.1";
$Username="reinicio";
$Pass="12345";
$api_puerto=8728;
$name="wlan2"; //
$API = new routeros_api();
$API->debug = true;
if ($API->connect($ipRouteros , $Username , $Pass, $api_puerto)){
$API->write ('/ip/dhcp-client/release', false);
$API->write ( '=.id=',3);
$API->read ( false );
}
else
{
$API->disconnect();
}
I have a question specifically in this line $ API-> write ('= .id =', 3) ;, how do I specify that I want to release the wlan3 interface?
Thank you very much once more
this is the answer of the debug
Connection attempt #1 to 192.168.17.1:8728... <>> [5/5] bytes read. >>> [5, 39]!done >>> [37/37] bytes read. >>> [37, 1]=ret=5c4f9601961333c7ae3c52186747afad <<< [6] /login <<< [14] =name=reinicio <>> [5/5] bytes read. >>> [5, 1]!done Connected... <<< [23] /ip/dhcp-client/release <<< [5] =.id= <>> [5/5] bytes read. >>> [5, 8]!done >>> [6/6] bytes read. >>> [6, 1].tag=3
, you should not send the parameter “3”, insted of that you have to first get the internal “.id” (also using the API).
A way to get the “.id”, maybe not the optimal, is as follows:
//Get the DHCP-CLIENT details that match with interface wlan1
$arrResult = $API->comm ( '/ip/dhcp-client/print', array ("?interface" => 'wlan1') );
Play around with the previous line of code, e.g you could send no parameters to get all DHCP-clients or search by your custom criteria.
Note that the arrResult variable will contain all the DHCP-clients that matched with the query. You could use this array to build a previous screen where the user can select the desired interface, this is up to you.
//Get DHCP-CLIENT details of all (empty array).
$arrResult = $API->comm ( '/ip/dhcp-client/print', array () );
I tested the following code and it releases the dhcp-client set on wlan1:
Hello Mr. Ochaconm, thank you very much for your help, without you I think I would have gone crazy, thanks to your examples I managed to solve my problem and everything is working as I wanted.