-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search by mac & read protected object #38
Comments
You should check that page in the wiki that says "API Reference". It has detailed information on all methods and classes in the package. In this case, you're asking about Util::getAll() and ResponseCollection. To answer your specific questions though, you can read a ResponseCollection as if you would read an array - a foreach loop, or a for loop with a count(), and as you can see in the reference, there are also a few extra methods for filtering it and sorting the responses. Each response in the ResponseCollection, you can also read as if you were reading an associative array (for properties), and there are a few extra methods for accessing things that are not properties (type and tag). So in its simplest form, you can think of a ResponseCollection as an array of associative arrays. e.g. foreach ($array as $response) {
foreach ($response as $propName => $propValue) {
echo 'The property "' . $propName . '" has a value "' . $propValue . '". ';
}
} And yes, just as you can use a "where" from a command line, you can use a $array = $util->setMenu('/ip dhcp-server lease')
->getAll(array(), RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D')); As you can see in the reference, the first argument is extra arguments to pass to the "print" request. |
On our company router we have two networks, public and private. I've connected to both for testing purposes. And when I search by MAC I get the following error:
Totally crashes my script. Is it possible for |
First off, assuming you used Util::find() with a Query (and you then passed the result to Util::get()), the cause is probably this issue. I'll release a new fixed version soon, though if you want it "now", you can use Composer with "dev-develop" as the version of "pear2/net_routeros" to get. But in general, yes, as the error message itself says, this is an uncaught exception, meaning you can catch it if you want, and deal with it, f.e. try {
$address = $util->get($util->find(RouterOS\Query::where('mac-address', 'B0:E8:92:30:C9:4D')), 'address');
} catch (RouterOS\RouterErrorException $e) {
echo 'Router message: ' . $e->getResponses()->getAllOfType(RouterOS\Response::TYPE_ERROR)->getProperty('message');
} |
Thanks. Error message is returned this way.
|
Hi,
When I print all the leases:
$array = $util->setMenu('/ip dhcp-server lease')->getAll();
I get an object like this, how can I read this:
And is it possible to pass a mac address here:
'/ip dhcp-server lease'
, so I will only get all this info for 1 mac address instead of all the clients?The text was updated successfully, but these errors were encountered: