P.D: I trying create 2 php, one of them to active an specific ethernet port, and another php to desactive it.
It’s my first project with mikrotik API :S
If you do “/interface ethernet ?”, you’ll see “disable” is a command. If you then do “/interface ethernet disable ?”, you’ll see it accepts “numbers” as an argument, which is the interface(s) to disable.
Thanks, but i still having problems. It’s my full code:
<?php require_once('routeros_api.class.php');
?>
<?php
$ipRouteros="192.168.2.1"; // tu RouterOS.
$Username="adminapi"; // usuario API
$pass="adminapi"; // contraseña del usuario API
$api_puerto=8728; // Puerto API por defecto
$API = new routeros_api();
$API->debug = false;
if ($API->connect($ipRouteros , $username , $pass, $api_puerto))
{
$API->write('/interface/ethernet/disable',false);
$API->write('=numbers=ether4',true);
}
$API->disconnect();
?>
<?php require_once('api_mt_include2.php'); ?>
<?php
////////////////////////////////////////////////////////////////////
// ESTE EJEMPLO SE DESCARGO DE www.tech-nico.com ///////////////////
// Creado por: Nicolas Daitsch. Guatrache. La Pampa ////////////////
// Contacto: administracion@tech-nico.com //////////////////////////
// RouterOS API: Busco interfaz ethernet y la activo o desactivo //
////////////////////////////////////////////////////////////////////
$ipRouteros="200.20.30.40"; // tu RouterOS.
$Username="blog.tech-nico.com";
$Pass="tupassword";
$api_puerto=8728;
$name="ether1"; // -------> aqui el nombre de tu interfaz!!
$API = new routeros_api();
$API->debug = false;
if ($API->connect($ipRouteros , $Username , $Pass, $api_puerto)) {
$API->write("/int/ether/getall",false);
$API->write('?name='.$name,true);
$READ = $API->read(false);
$ARRAY = $API->parse_response($READ);
if(count($ARRAY)>0){ // SI LA INTERFAZ EXISTE!!
$id_interfaz = $ARRAY[0][".id"];
$disabled = $ARRAY[0]["disabled"];
if ($disabled=="true"){ // SI ESTA DESACTIVADA!!
$API->write("/int/ether/enable",false);
$API->write("=.id=".$id_interfaz,true);
echo '<strong>'.$name.'</strong> esta ahora activada <img alt="" src="icon_led_green.png" /> ';
}else{ // SI ESTA ACTIVADA!!
$API->write("/int/ether/disable",false);
$API->write("=.id=".$id_interfaz,true);
echo '<strong>'.$name.'</strong> esta ahora desactivada <img alt="" src="icon_led_grey.png" /> ';
}
$READ = $API->read(false);
}else{ //el servidor API esta of line
echo 'Ocurrio un error: '.$ARRAY['!trap'][0]['message'];
}
}else{
echo "<span style="color: #ff0000;">La conexion ha fallado. Verifique si el Api esta activo.</span>";
}
$API->disconnect();
?>
hola buenas tarde consulto como se puede bloquear las interfaces o puertos ethernet del mikrotik, en una franja horaria.. por ejemplo a la madrugada desde ya gracias