Newby on MikroTik Forum. I have a bit of a challenge here. I have been trying to get a script running to remove the IP hotspot host according to its DHCP lease if the Host is not authorized in the hotspot host.
I have tried numerous ways in writing the script but only partially working, it only deletes the IP hotspot Host that is not authorized.
I stumbled upon your post while searching for a similar script. After some trial and error, I found a script that seems to be effective in removing DHCP server lease entries after querying an unauthorized list from /ip hotspot host:
# This script is designed to manage DHCP server leases by removing entries that do not correspond to authorized clients. It iterates through dynamic
# DHCP leases and checks if each lease's IP and MAC address match an entry in the authorized list from the /ip hotspot host. If no match is found,
# indicating an unauthorized client, the script removes the lease entry from the DHCP server lease.
:foreach lease in=[/ip dhcp-server lease find dynamic] do={
:local ip [/ip dhcp-server lease get $lease address]
:local mac [/ip dhcp-server lease get $lease mac-address]
:local authorized [/ip hotspot host find where address=$ip and mac-address=$mac and bypassed=no]
:if ([:len $authorized] = 0) do={
/ip dhcp-server lease remove $lease
:log info "Removed unauthorized DHCP lease for ADDRESS: $ip, MAC: $mac"
}
}
However, I still need to verify if it behaves as expected in my specific configuration. If you have a moment, could you please test it and let me know if you encounter any issues?