How to perform a "dhcp-server lease find"?

I’ve got the latest RouterOS v6.28. And I want to make some scripts to manage DHCP records externally.
I tried to do it in CLI first:

[admin@] > /ip dhcp-server lease print
Flags: X - disabled, R - radius, D - dynamic, B - blocked
 #   ADDRESS                                                 MAC-ADDRESS       HOST-NAME               SERVER               RATE-LIMIT               STATUS
 0   10.0.0.1                                                11:11:11:11:11:11                                                                       waiting
 1   10.0.0.2                                                22:22:22:22:22:22                                                                       waiting
[admin@] > /ip dhcp-server lease find mac-address=11:11:11:11:11:11
[admin@] > /ip dhcp-server lease find ?
Returns list of items which property values are equal to given ones. Returns list of all items if no arguments are given.
<where> --
[admin@] > /ip dhcp-server lease find

Why is there no any output from find commands?

Then I tried to use PHP API:

$dhcpRequest = new RouterOS\Request('/ip dhcp-server lease find');
$results = $client->sendSync(
               $dhcpRequest
);
print_r($results);

[ret] => *1;*2



$dhcpRequest = new RouterOS\Request('/ip dhcp-server lease find');
$results = $client->sendSync(
                $dhcpRequest->setArgument('mac-address','11:11:11:11:11:11')
);
print_r($results);

[message] => unknown parameter

What am I doing wrong? Please help me. Is there any more detailed documentation? I’ve read wiki and some PDF, but there is no detailed info on find syntax. I can’t figure out how it works.

find has no output, only a return value, try this instead:

:put [/ip dhcp-server lease find]

And this is the right way to make an API query:

$dhcpRequest = new RouterOS\Request('/ip dhcp-server lease find',
    RouterOS\Query::where('mac-address', '22:22:22:22:22:22')
);

Last I checked, for some reason, “find” commands don’t accept queries, even though their CLI equivalents have “where”… Or do they now?

As you’ve already found out, the return value is available in a property called “ret”, and as psamsig pointed out, even in CLI, “find” has no output, and only has a returned value you can store in a variable or output or whatever.


If you want to find specific IDs with a query, you can instead use “print”, and then examine all “.id” properties returned. For convenience, the API client also has an Util class that includes a find() method. This method does just that under the hood, ultimately returning what “find” with a query would, e.g.:

$util = new RouterOS\Util($client);
$ids = $util->setMenu('/ip dhcp-server lease')->find(
    RouterOS\Query::where('mac-address', '22:22:22:22:22:22')
);
var_dump($ids);//Should output something like string(2) "*2"