dhcp-server lease find where host-name (contains|in) [stuff] doesn't return anything?

How can I search in the leases list if I want to find a host-name that contains something?


But also, on the command line even,

/ip dhcp-server lease print where host-name = “something” ;; spits an error on “=”
/ip dhcp-server lease print where host-name is “something” ;; no error but no result, and ‘is’ is colored red
/ip dhcp-server lease print where host-name in “something” ;; no error and ‘in’ is colored yellow, but the result still is empty.
/ip dhcp-server lease get [find where host-name in “something”] ;; ‘in’ colored yellow, but the answer is ‘no such item’.

What am I missing?
(also need this to work in the on-lease script).

(ROS 6.47.9)

print is not the right way to do it, you need to use find and get.

Eks

/ip dhcp-server lease find where host-name="Chromecast"

Will find all with name “Chromecast”

To get some output, you need to use put

:put [/ip dhcp-server lease find where host-name="Chromecast"]

This will get all ID, so you then need to put it in a foreach loop

{
:foreach i in=[/ip dhcp-server lease find where host-name="Chromecast"] do {
	:put [/ip dhcp-server lease get $i]

}
}

All in one line:

/ip dhcp-server lease;:foreach i in=[find where host-name="Chromecast"] do={:put [get $i]}

Thanks, this finds and prints all that the host-name is exact; But what if I want it to ‘contain’ the part string? it is possible on Winbox… (ok I know this may mean nothing but still.)

(tried
/ip dhcp-server lease;:foreach i in=[find where host-name in “part i want to find”] do={:put [get $i]}
/ip dhcp-server lease;:foreach i in=[find where “part i want to find” in host-name] do={:put [get $i]}
no results?

really you try “random” commands?

not on ‘production’ equipment :slight_smile: but yes ? Also it’s not ‘random’ if I’m trying get it to do something :slight_smile:

one moment, please…

on terminal:

all is case-sensitive

exact host name;
/ip dhcp-server lease print where host-name=“whaiIwant”

different host name;
/ip dhcp-server lease print where host-name!=“whaiIwant”

partial / regexp hostname with partial
/ip dhcp-server lease print where host-name~“DESKTOP”
(for ex. DESKTOP-48UDNGH, DESKTOP-ICQPPS7, etc.)

partial / regexp hostname with regexp
/ip dhcp-server lease print where host-name~“PC-0..”
(for ex. PC-001, PC-002, PC-0XS, etc.)

partial / regexp hostname with NOT partial
/ip dhcp-server lease print where !(host-name~“DESKTOP”)

partial / regexp hostname with NOT regexp
/ip dhcp-server lease print where !(host-name~“PC-0..”)

FOUND IT!

/ip dhcp-server lease;:foreach i in=[find where host-name~“part i want to find”] do={:put [get $i]}

so it’s the ~ operator according to wiki:

“~” binary operator that matches value against POSIX extended regular expression

Sorry for the noise :slight_smile:

This, thank you too I found in the wiki at the same time as you’ve posted the answer :slight_smile: thank you for sharing :slight_smile: