Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 17957

Scripting • Re: script for monitoring dhcp clients by MAC address

$
0
0
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:
Code:
: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.

Statistics: Posted by mikefox — Wed Dec 13, 2023 9:47 am



Viewing all articles
Browse latest Browse all 17957

Trending Articles