Community discussions

MikroTik App
 
pe1chl
Forum Guru
Forum Guru
Topic Author
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

SNMP queries for MAC->port mapping table

Fri Jul 03, 2015 10:23 pm

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?
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Sat Jul 04, 2015 2:29 pm

Have you looked at provided data by snmp walk?
 
pe1chl
Forum Guru
Forum Guru
Topic Author
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP queries for MAC->port mapping table

Sat Jul 04, 2015 6:01 pm

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...
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Sat Jul 04, 2015 6:52 pm

Then it is most likely not there.
 
pimmie
newbie
Posts: 47
Joined: Fri Mar 27, 2015 4:51 pm

Re: SNMP queries for MAC->port mapping table

Tue Sep 01, 2015 11:49 pm

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?
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: SNMP queries for MAC->port mapping table

Thu Sep 03, 2015 1:35 pm

RouterOS will return all OIDs using walk (bulkwalk for faster results)
 
pimmie
newbie
Posts: 47
Joined: Fri Mar 27, 2015 4:51 pm

Re: SNMP queries for MAC->port mapping table

Thu Sep 03, 2015 3:32 pm

the oid mac-address / .1.3.6.1.2.1.2.2.1.6.1
Sorry, I copied the wrong oid. It should be .1.3.6.1.2.1.17.4.3.1.2
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: SNMP queries for MAC->port mapping table

Thu Sep 03, 2015 4:22 pm

we are checking is that is possible.
 
marrold
Member
Member
Posts: 427
Joined: Wed Sep 04, 2013 10:45 am

Re: SNMP queries for MAC->port mapping table

Thu Sep 03, 2015 4:27 pm

/ interface bridge host print
Shows which MAC address is attached to which bridged interface. But it doesn't look like you can pull this via SNMP
[admin@#########] > / interface bridge host print
Flags: L - local, E - external-fdb
  BRIDGE                                                                                         MAC-ADDRESS       ON-INTERFACE                                                                                         AGE
L Br-V129                                                                                        D4:CA:6D:E7:58:73 Restricted LAN [01]                                                                                  0s
  Br-V130                                                                                        00:1B:67:14:C2:B0 Default LAN [01]                                                                                     0s
  Br-V130                                                                                        28:92:4A:34:4B:66 Default LAN [01]                                                                                     1m
  Br-V130                                                                                        A0:F3:C1:CE:3B:AC Default LAN [01]                                                                                     1s
  Br-V130                                                                                        AC:CA:54:00:0E:26 Default LAN [01]                                                                                     1s
 
pimmie
newbie
Posts: 47
Joined: Fri Mar 27, 2015 4:51 pm

Re: SNMP queries for MAC->port mapping table

Sat Sep 05, 2015 11:56 am

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.
 
mp412
just joined
Posts: 4
Joined: Thu May 18, 2017 3:17 am

Re: SNMP queries for MAC->port mapping table

Sat Jun 29, 2019 2:03 am

any update on viewing mac host mac on snmp yet?
or still need to wait until version 7?
 
pe1chl
Forum Guru
Forum Guru
Topic Author
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP queries for MAC->port mapping table

Sat Jun 29, 2019 11:10 am

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: SNMP queries for MAC->port mapping table

Sat Jun 29, 2019 1:33 pm

How to then get mac on interface using SNMP?

This works from cli:
/interface bridge host print
This gives nothing:
/interface bridge host print oid
This gives nothing
snmpget -v 2c -c public myhost .1.3.6.1.2.1.17.4.3.1.2
 
pe1chl
Forum Guru
Forum Guru
Topic Author
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP queries for MAC->port mapping table

Sat Jun 29, 2019 2:45 pm

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
 
imadloo
just joined
Posts: 5
Joined: Wed Dec 12, 2018 9:47 pm

Re: SNMP queries for MAC->port mapping table

Wed Jul 01, 2020 9:35 pm

I noticed a problem in version 6.47.
RouterOS 6.47 (stable) on RB2011iLS

Mapped ports from the command:
iso.3.6.1.2.1.17.4.3.1.2

are shifted by 7

Example:
# snmpwalk -v2c -c public x.x.x.x 1.3.6.1.2.1.17.4.3.1.1.240.77.162.90.140.137
iso.3.6.1.2.1.17.4.3.1.1.240.77.162.90.140.137 = Hex-STRING: F0 4D A2 5A 8C 89
# snmpwalk -v2c -c public x.x.x.x 1.3.6.1.2.1.17.4.3.1.2.240.77.162.90.140.137
iso.3.6.1.2.1.17.4.3.1.2.240.77.162.90.140.137 = INTEGER: 9
and really the mac address is on the ether1 port, i.e.
1.3.6.1.2.1.31.1.1.1.1.2 = STRING: "ether1"

In other devices, yet another shift:
RouterOS 6.47 (stable) on RB750Gr3
# snmpwalk -v2c -c public x.x.x.x .1.3.6.1.2.1.17.4.3.1.1.248.209.17.164.72.123
iso.3.6.1.2.1.17.4.3.1.1.248.209.17.164.72.123 = Hex-STRING: F8 D1 11 A4 48 7B
# snmpwalk -v2c -c public x.x.x.x .1.3.6.1.2.1.17.4.3.1.2.248.209.17.164.72.123
iso.3.6.1.2.1.17.4.3.1.2.248.209.17.164.72.123 = INTEGER: 0
# snmpwalk -v2c -c public x.x.x.x .1.3.6.1.2.1.31.1.1.1.1.2
iso.3.6.1.2.1.31.1.1.1.1.2 = STRING: "ether2"
and really the mac address is on the ether2 port, i.e.

are shifted by 2
 
pe1chl
Forum Guru
Forum Guru
Topic Author
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: SNMP queries for MAC->port mapping table

Wed Jul 01, 2020 9:53 pm

You are right, it does not work correctly anymore...
 
User avatar
rururudy
newbie
Posts: 30
Joined: Thu Aug 04, 2016 10:57 pm
Location: San Francisco
Contact:

Re: SNMP queries for MAC->port mapping table

Fri Dec 09, 2022 12:15 am

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
====================== MAC table  =======================
SNMPv2-SMI::mib-2.17.4.3.1.2.8.134.59.81.162.182 = INTEGER: 3
SNMPv2-SMI::mib-2.17.4.3.1.2.76.94.12.214.120.33 = INTEGER: 7
SNMPv2-SMI::mib-2.17.4.3.1.2.212.202.109.162.157.64 = INTEGER: 0
======================= Interface Index    =======================
IF-MIB::ifName.1 = STRING: sfp-unused
IF-MIB::ifName.2 = STRING: 01g-uplink
IF-MIB::ifName.3 = STRING: 02g
IF-MIB::ifName.4 = STRING: 03g
IF-MIB::ifName.5 = STRING: 04g
IF-MIB::ifName.6 = STRING: 05g
IF-MIB::ifName.7 = STRING: 06f
IF-MIB::ifName.8 = STRING: 07f
IF-MIB::ifName.9 = STRING: 08f
IF-MIB::ifName.10 = STRING: 09f
IF-MIB::ifName.11 = STRING: 10f-POE
IF-MIB::ifName.12 = STRING: bridge-local
======================= Bridge to Port Map =======================
SNMPv2-SMI::mib-2.17.1.4.1.2.1 = INTEGER: 3
SNMPv2-SMI::mib-2.17.1.4.1.2.2 = INTEGER: 4
SNMPv2-SMI::mib-2.17.1.4.1.2.3 = INTEGER: 5
SNMPv2-SMI::mib-2.17.1.4.1.2.4 = INTEGER: 6
SNMPv2-SMI::mib-2.17.1.4.1.2.5 = INTEGER: 7
SNMPv2-SMI::mib-2.17.1.4.1.2.6 = INTEGER: 1
SNMPv2-SMI::mib-2.17.1.4.1.2.7 = INTEGER: 2
SNMPv2-SMI::mib-2.17.1.4.1.2.8 = INTEGER: 8
SNMPv2-SMI::mib-2.17.1.4.1.2.9 = INTEGER: 9
SNMPv2-SMI::mib-2.17.1.4.1.2.10 = INTEGER: 10
SNMPv2-SMI::mib-2.17.1.4.1.2.11 = INTEGER: 11

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:
Last edited by rururudy on Fri Dec 09, 2022 1:33 am, edited 1 time in total.
 
User avatar
rururudy
newbie
Posts: 30
Joined: Thu Aug 04, 2016 10:57 pm
Location: San Francisco
Contact:

Re: SNMP queries for MAC->port mapping table

Fri Dec 09, 2022 12:21 am

Use this script to help you out. Usage: ./mikrotik-walk-test.sh IP_OF_DEVICE. Change the COMM to your community name.
# mikrotok-walk-test.sh - walk those oids!
IP=$1
COMM=YourSNMPcommunity

echo "======================= OS Version $IP =======================";
snmpwalk -v2c -c $COMM  $IP .1.3.6.1.4.1.14988.1.1.7.4.0
echo "======================= MAC table          =======================";
snmpwalk -v2c -c  $COMM $IP .1.3.6.1.2.1.17.4.3.1.2
echo "======================= Interface Index    =======================";
snmpwalk -v2c -c  $COMM $IP .1.3.6.1.2.1.31.1.1.1.1
echo "======================= Bridge to Port Map =======================";
snmpwalk -v2c -c  $COMM $IP .1.3.6.1.2.1.17.1.4.1.2
# Updated with these next two queries to this post oct, 17, 2023!
echo "======================= IP To PhyAddress   =======================";
snmpwalk -v2c -c $COMM $IP IP-MIB::ipNetToMediaPhysAddress
echo "======================= PhyAddress descr   =======================";
snmpwalk -v2c -c $COMM $IP IF-MIB::ifDescr
Last edited by rururudy on Wed Oct 18, 2023 3:14 am, edited 1 time in total.
 
User avatar
rururudy
newbie
Posts: 30
Joined: Thu Aug 04, 2016 10:57 pm
Location: San Francisco
Contact:

Re: SNMP queries for MAC->port mapping table

Fri Dec 09, 2022 12:30 am

any update on viewing mac host mac on snmp yet?
It is possible with 6.x and 7.x.
Depending on the version, you need these three OIDs:
  • .1.3.6.1.2.1.17.4.3.1.2 MAC table
  • .1.3.6.1.2.1.17.1.4.1.2 BridgePortIndex to InterfaceIndex Mapping
  • .1.3.6.1.2.1.31.1.1.1.1 Interface
 
User avatar
rururudy
newbie
Posts: 30
Joined: Thu Aug 04, 2016 10:57 pm
Location: San Francisco
Contact:

Re: SNMP queries for MAC->port mapping table

Wed Oct 18, 2023 3:15 am

To get VLAN information, you need to query snmpwalk -v2c -c $COMM $IP IP-MIB::ipNetToMediaPhysAddress

Who is online

Users browsing this forum: No registered users and 15 guests