For generating documentation about “which device is connected to what port” I have written some scripts in the
past that use SNMP to retrieve information from routers and switches.
With switches, this script snmpwalks mib-2.17.4.3.1.2 to retrieve a “MAC address to port table”.
In plain switches, this makes it possible to see which MAC address is connected to which port.
Of course a MikroTik RB2011 combines both router and switch functionality.
When the switches are disabled and all ethernet ports are connected to bridges or are used for routing, the
above snmp id retrieves the information for the ethernet interfaces of the router, much like it can be retrieved
for the ports of a managable switch.
However, the RB2011 has two switch chips as well. When these are enabled (by setting “master port” settings of
some ethernet ports), the above snmp query returns the master port number for all devices connected via such
a switching setup. I can understand that when the information really is retrieved at the ethernet port level.
However, when looking in the admin interface, it is possible to see what physical port the MAC addresses are
really connected to.
Is it possible to retrieve that information via SNMP?
Yes, and I have not yet found it.
However, my experience is that not all data is always returned in snmpwalk for some devices.
You may have to use a different starting point or even a different community name to find everything…
I have been using the oid mac-address / .1.3.6.1.2.1.2.2.1.6.1 as well to monitor connected devices on my switches and experienced the same issue with RouterOS as pe1chl describes.
To me this sounds as a bug in the system. As pe1chl indicates the correct information is actually available in WinBox (Switch → Host), so why not in snmp?
Could somebody from Mikrotik have a look at this if the current behaviour is correct or not?
Resolution I received by email from Mikrotik support:
in RouteroS 6.x it will not be possible to bring all this information together. You will have to wait till RouterOS 7.x release to see what hosts on what port are available.
Well, that thread was started a long time ago and actually the problem has solved itself by the change from “master-port” to “bridge” some versions ago.
Use snmpwalk instead of snmpget!
You will get a list of items starting from .1.3.6.1.2.1.17.4.3.1.2 but with 6 extra numbers appended which are the MAC address bytes in decimal.
The value of each item is an integer which is the interface number.
To get the mapping of interface number to interface name you need to walk other OIDs like .1.3.6.1.2.1.2.2.1.2 or .1.3.6.1.2.1.31.1.1.1.1
Older version (6.46.8 and earlier) would return the ‘interfaceIndex’ when querying .1.3.6.1.2.1.17.4.3.1.2 via SNMP.
Now (6.49.5 for example) the query returns the ‘bridgeIndex’.
To convert the bridgeIndex to the interfaceIndex you need to use this OID: .1.3.6.1.2.1.17.1.4.1.2
Decoding the mac address, mapping bridge to index, you can determine that:
.1.3.6.1.2.1.17.4.3.1.2.76.94.12.214.120.33 = 4c:5e:0c:d6:78:21 on bridge: 7, port: 2
.1.3.6.1.2.1.17.4.3.1.2.8.134.59.81.162.182 = 08:86:3b:51:a2:b6 on bridge: 3, port: 5
.1.3.6.1.2.1.17.4.3.1.2.212.202.109.162.157.64 = d4:ca:6d:a2:9d:40 on bridge: 0, port: UNDEFINED
Notes:
To understand the mapping OID, take this example: SNMPv2-SMI::mib-2.17.1.4.1.2.1 = INTEGER: 3
See the bolded values? Bridge Index 1 maps to Interface Index 3: