Community discussions

MikroTik App
 
JAN1778456531
just joined
Topic Author
Posts: 1
Joined: Sat Nov 25, 2023 5:26 pm

script for monitoring dhcp clients by MAC address

Sat Nov 25, 2023 5:36 pm

Hello everyone, I need help with monitoring new DHCP clients by MAC address. Every new client that connects must fulfill a condition or a filter where the initial part of the MAC address, for example 12:34:56:##:##:##, which MAC address does not have an initial part equal to the filter, will be included in the address list as not allowed. Please, could something like this be done and how?
Thanks in advance for your help.
 
mikefox
just joined
Posts: 4
Joined: Wed Dec 13, 2023 9:37 am

Re: script for monitoring dhcp clients by MAC address

Wed Dec 13, 2023 9:47 am

Hi, yes, it is possible to monitor new DHCP clients by MAC address and apply a filter based on the initial part of the MAC address. You can achieve this in MikroTik RouterOS by utilizing DHCP Server Lease Scripting.

Here's an example script that demonstrates how to accomplish this:
:local macFilter "12:34:56"

:if ($leaseBound = "1") do={
  :local macAddress [:toarray [:pick $leaseMAC 0 8]]
  
  :if ($macAddress != $macFilter) do={
    /ip firewall address-list add address=$leaseActIP list=not-allowed
    :log warning "New DHCP client with MAC address $leaseMAC added to not-allowed list."
  }
}
In this script:

1. Set the macFilter variable to the desired initial part of the MAC address that you want to filter.
2. The script checks if a DHCP lease has been bound ($leaseBound = "1").
3. It extracts the first 8 characters of the MAC address using [:pick $leaseMAC 0 8].
4. If the extracted MAC address ($macAddress) does not match the macFilter, it adds the corresponding IP address ($leaseActIP) to the "not-allowed" address list and logs a warning message.
You can customize the script further based on your specific requirements. For example, you can change the name of the address list (not-allowed) or modify the log message according to your preferences.

Who is online

Users browsing this forum: No registered users and 10 guests