Community discussions

MikroTik App
 
M3Tech
just joined
Topic Author
Posts: 15
Joined: Sat Oct 24, 2015 2:00 am

Tracking MAC-Address / Interface Pairs

Thu Aug 31, 2017 2:10 am

I'm not sure if the following is possible, I certainly have failed to make it work with my limited scripting knowledge, and was hoping someone can point me in the right direction or tell me it's not feasible.

I'd like to track MAC-Address to port's for reference, and to avoid manual lookup when needed. (I support a lot of clients that have folks that will re-cable without approval / documenting changes).

For one client, the relevant info is in /interface bridge host print, but I can not figure out how to extract the elements (mac-address, on-interface) for further processing or storage. I'm aware that some interfaces will have multiple mac-addresses, etc.

Any assistance, or indication I'm wasting my time, would be appreciated.
 
User avatar
PaulsMT
MikroTik Support
MikroTik Support
Posts: 282
Joined: Tue Feb 10, 2015 3:21 pm

Re: Tracking MAC-Address / Interface Pairs

Thu Aug 31, 2017 12:38 pm

I'm not sure if the following is possible, I certainly have failed to make it work with my limited scripting knowledge, and was hoping someone can point me in the right direction or tell me it's not feasible.

I'd like to track MAC-Address to port's for reference, and to avoid manual lookup when needed. (I support a lot of clients that have folks that will re-cable without approval / documenting changes).

For one client, the relevant info is in /interface bridge host print, but I can not figure out how to extract the elements (mac-address, on-interface) for further processing or storage. I'm aware that some interfaces will have multiple mac-addresses, etc.

Any assistance, or indication I'm wasting my time, would be appreciated.
This would require you to create a script that regulary walks trought the bridge host table, and store new interface recod for each MAC.

First create array where you will store interface records for each MAC address.
:global arr {mac="interfaces"};
Add script which will look for new mac-interface pairs, this part should be added in scheduler for regular execution
    :global arr;
    foreach host in=[interface bridge host find] do={
        :local mac [/interface bridge host get $host mac-address]
        :local iface [/interface bridge host get $host on-interface]

        if (($arr->"$mac")~"$iface;") do={:put "Interface already on list";} else={
            :put "New inteface for mac $mac"
            :set ($arr->"$mac") (($arr->"$mac")."$iface;")
        }
    } 
print out results, or store them on file
    foreach k,v in=$arr do={
        :put ("$k=$v")
    }
https://wiki.mikrotik.com/wiki/Manual:System/Scheduler
https://wiki.mikrotik.com/wiki/Manual:Scripting

To exclude local mac records, you can use:
/interface bridge host find where !local
 
M3Tech
just joined
Topic Author
Posts: 15
Joined: Sat Oct 24, 2015 2:00 am

Re: Tracking MAC-Address / Interface Pairs

Thu Aug 31, 2017 5:17 pm

Thank you for the very detailed response PaulsMT.

I regularly find new reasons to love RouterOS, and my customer base (I work at a regional VAR + MSP) is gradually migrating to routerboard hardware at my near-insistence.

Who is online

Users browsing this forum: No registered users and 10 guests