The DHCP server does not tell you if a system is connected or not. The DHCP lease will remain in the server for as long as the lease time is set, even when the client has left.
I needed to do what you want (to check if certain devices are online or not) and I used this script fragment:
:if ([:len [/ip arp find where mac-address=$Mac and complete]] > 0) do={
:set Present 1;
} else={
:if ([:len [/ipv6 neighbor find where mac-address=$Mac]] > 0) do={
:set Present 1;
}
}
# when not present in ARP table anymore, try a ping to make sure
if ($Present = 0) do={
/ping [/ip dhcp-server lease get [find mac-address=$Mac] address] count=2;
:if ([:len [/ip arp find where mac-address=$Mac and complete]] > 0) do={
:set Present 1;
}
}
This checks if $Mac is connected and sets $Present if so. It was arrived at after a lot of experiments... this is running on a router which has both IPv4 and IPv6, you can drop the ipv6 check when you do not have that.
Basically it checks if the address is present in the ARP or IPv6 neighbor table, and if not it looks up the latest issued DHCP lease, and pings the device at that address, then checks if it now appears in the ARP table.