Community discussions

MikroTik App
 
vilik77
just joined
Topic Author
Posts: 1
Joined: Fri Nov 24, 2023 1:36 am

Disabling a port based on MAC address

Fri Nov 24, 2023 1:48 am

Has anyone tried such a script? It doesn't seem to work for me.
Is it possible for it to work like this?
i need disable port if mac addres is not in the list. thx
:local allowedMacs {"00:11:22:33:44:55" "AA:BB:CC:DD:EE:FF"};
:local portNumber "ether1"; 

:local incomingMac [/interface ethernet switch port find mac-address=\
    [:tostr [:pick $[/interface ethernet switch port get $portNumber mac-address] 0 17]]]

:if ([:len $incomingMac] = 0) do={
    :log info "Unknown MAC address connected to port $portNumber. Port disabled."
    /interface ethernet switch port set $portNumber disabled=yes
} else={
    :local isAllowed false
    :foreach mac in=$allowedMacs do={
        :if ($mac = $incomingMac) do={
            :set isAllowed true
        }
    }
    
    :if ($isAllowed = false) do={
        :log info "Unauthorized MAC address connected to port $portNumber. Port disabled"
        /interface ethernet switch port set $portNumber disabled=yes
    } else={
        :log info "Authorized MAC address connected to port $portNumber. Port enabled"
        /interface ethernet switch port set $portNumber disabled=no
    }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Disabling a port based on MAC address

Fri Nov 24, 2023 11:11 am

Who did you take us for?
Do you copy scripts from unspecified sources and should we fix them for you?
Put the link to where you got the script.

Who is online

Users browsing this forum: No registered users and 11 guests