Hi All
How to filter out just the Flag Value ( whether an element is disabled or enabled ) by script.
Any help is welcome.
Abhishek
:local disabledItems [print as-value where disabled=yes];
:local enabledItems [print as-value where disabled=no];
:foreach item in=[print as-value] do={
:if ("yes" = ($item->"disabled") and "XX.XX.XX.XX" = ($item->"address")) do={
#IP is disabled
} else={
#Another IP, or the IP is enabled
}
}
Depends on what you want to do with the matches.I think using foreach is not required here.
Using the API protocol.How to embed the above code in PHP ?
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
$util = new RouterOS\Util($client = new RouterOS\Client('router-ip', 'admin', 'password'));
$util->setMenu('/ip hotsopt ip-binding');
foreach ($util->getAll() as $item) {
if ('yes' === $item('disabled') && 'XX.XX.XX.XX' === $item('address')) {
//IP is disabled
} else {
//Another IP, or IP not disabled
}
}
<?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
$util = new RouterOS\Util($client = new RouterOS\Client('router-ip', 'admin', 'password'));
$util->setMenu('/ip hotsopt ip-binding')->remove(
$util->find(
RouterOS\Query::where('disabled', 'yes')->andWhere('address', 'XX.XX.XX.XX')
)
);