Community discussions

MikroTik App
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

dhcp lease with know MAC set to queue

Sun Feb 09, 2020 10:54 pm

Hi guys, i want to automate script which are going to queue ip whenever is come to dhcp lease, reason is simple. I have a bunch of rotuers and one device is going to be on all that routers attached. So I dont want to queue it all 1 by one.
I stuck here:

I have part of good output for the appropriate mac
ip dhcp-server lease print where mac-address~"^AA:BB:CC"                      
Flags: X - disabled, I - invalid, H - DHCP, D - dynamic, P - published, C - complete 
 #    ADDRESS         MAC-ADDRESS       INTERFACE                                                                       
 0 DC 10.11.138.130   AA:BB:CC:D7:08:35 lan_bridge                                                                      
 1 DC 10.11.138.131   AA:BB:CC:08:19:BF lan_bridge         
 
So idea is to use something like this into dhcp lease script
:local queueName "Client-$leaseActMAC";
 
:local ipAdd "$leaseActIP/32"; 

:if ([:len [/queue simple find name=$queueName]] = 0) do={
:log info "No Queue";
        /queue simple add name=$queueName target=($ipAdd) limit-at=10M/4M max-limit=10M/4M comment=[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name];
    } else={
:log info "exists";
:local ada [/queue simple get [find name=$queueName] target];
        :log info "existing $ada";
        :if ($ada = $ipAdd) do={
            :log info "IP same $ada";
        } else={
            /queue simple set target=($ipAdd) [find name=$queueName];
        }
}
but this is for all clients.
How can I use it only for IP which mac starts with AA:BB:CC

Who is online

Users browsing this forum: VirtualEvan and 42 guests