Community discussions

MikroTik App
 
User avatar
Jotne
Forum Guru
Forum Guru
Topic Author
Posts: 3300
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Getting hostname for wifi clients from DHCP table

Fri Dec 15, 2023 2:11 am

I am struggling to get this to work.
What I need is the get the client name from the DHCP table fro each devices in the Wifi registration table.
Only first device gets listed, then scripts stops with "no such item"
I now all (just two for test) has DHCP hostname and both should be listed.

Any idea on what has gone wrong?
{
:local hostName 
/interface wireless registration-table
:foreach i in=[find] do={
:put ".id=$i;ap=$([get $i ap]);interface=$([get $i interface]);mac-address=$([get $i mac-address]);signal-strength=$([get $i signal-strength]);tx-rate=$([get $i tx-rate]);uptime=$([get $i uptime]);script=wifi;$([/ip dhcp-server lease get [find where mac-address=[get $i mac-address]] host-name ])"
}
}
Edit some testing:

:put [find]
give
*2;*3 so two devices.

This works fine for *2
:put [/ip dhcp-server lease get [find where mac-address=[get *2 mac-address]] ]
gives all DHCP including host-name

But for *3 it fails:
giving no such item

But both
:put [get *2 mac-address]
and
:put [get *3 mac-address]
works fine

Also using the mac directly works fine for both:
:put [/ip dhcp-server lease get [find where mac-address=4A:2F:D7:B1:03:xx] host-name]

RuterOS 7.12.1 on TB751UI

Who is online

Users browsing this forum: No registered users and 2 guests