Page 1 of 1

Locating MAC addresses in the network - MikroTik

Posted: Wed Feb 02, 2022 1:29 pm
by Tomas
This is an example of how to find where a particular MAC address is connected to in your network. These scripts can be used to answer the "Which port is this MAC connected to?" question (assuming that port is on a RouterOS device).

You can create a Mass Config Push with this preset and target all the MikroTiks in your network to find the MAC.

Here is a lookup for use with Tik bridging. Looking into the bridge L2FDB, and if the MAC exists on a port, and is the only MAC on that port, we assume that is the endpoint port for that MAC (the port the device that owns that MAC is connected to):

Code: Select all

{
:local macToFind "AA:BB:CC:DD:EE:FF"

/interface bridge host
:foreach i in=[find mac-address=$macToFind] do={
  :if ([:len [find on-interface=[get $i on-interface]]] = 1) do={
    :put ("Found $macToFind as only host on interface " . [get $i on-interface])
  }
}
}
An alternative approach can be used if we know that the MAC we are looking for is a client connected to one of our APs. In this case, we can use the client registration table to look up our client's AP:

Code: Select all

{
:local macToFind "AA:BB:CC:DD:EE:FF"

/interface wireless registration-table
:foreach i in=[find mac-address=$macToFind] do={
  :put ("Found $macToFind on interface " . [get $i interface])
}
}