Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MAC or IP Addresses of devices connected to a switch using SNMP?

Tags:

snmp

Using SNMP, how do I get the MAC address of the device connected to each port on the switch? We're using HP ProCurve Switches.

I tried using the OID dot1dTpFdbPort but that seems to be giving me the MAC address of every device that's in communication with the switch, not just connected to it.

I'm trying to find the OID that will give me ports 1-48 in a list, and for each port, the MAC (or IP address) of the device connected to that port.

Thanks!

like image 607
Danny Ackerman Avatar asked Aug 31 '12 14:08

Danny Ackerman


People also ask

How do you find the IP address of a device connected to a switch?

To determine the IP address, go to the Layer-3 device that you switch is connected to. In the Layer-3 device ( mostly a router or layer 2.5 switch ) run the “show ip arp” command. And there it is ! You will find the ip address matching with your client's MAC address.

How do I find the IP address of a device connected to a Cisco switch?

Perform a show mac address-table interface <switchport> on the switch that has the device(s) connected to it. Then go to the router for the VLAN specified in the previous command and perform a show ip arp vlan <vlan#> | include <mac-address> . That will give you the IP address for the device.

Does a switch track MAC address?

Switches need to keep track of the MAC addresses of all connected devices. Without the learning function, the switch would not know to which port the destination device is connected. At the center of the learning function is a part of the switch's memory. We refer to this memory location as the MAC Address Table.


2 Answers

Thank you so much raz3r for your answer. It works like a charm !

From your linux server :

$ snmpwalk -v 1 -c public xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.2 | grep "INTEGER: 11"

(port number 11)

Will return :

SNMPv2-SMI::mib-2.17.4.3.1.2.44.118.138.64.143.95 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.56.170.60.108.174.57 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.104.181.153.172.54.237 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.120.172.192.143.226.236 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.124.195.161.20.109.76 = INTEGER: 11
SNMPv2-SMI::mib-2.17.4.3.1.2.152.75.225.59.127.180 = INTEGER: 11

Then you can do this to find which Mac Address is connected :

$ snmpwalk -v 1 -c public xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.1 | grep "152.75.225.59.127.180"

Return mac address :

SNMPv2-SMI::mib-2.17.4.3.1.1.152.75.225.59.127.180 = Hex-STRING: 98 4B E1 3B 7F B4

You can make a script.sh to do this...

like image 142
N P Avatar answered Oct 12 '22 07:10

N P


You were almost there :) The dot1dTpFdbPort is exactly what are you looking for, the only thing that you need is a link to the real port index.

First, take the value given by dot1dTpFdbPort.

Now query the dot1dBasePortIfIndex with the value you took before.

Let's make an example:

snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.4.3.1.1

SNMPv2-SMI::mib-2.17.4.3.1.1.0.2.253.255.213.15 = Hex-STRING: XX XX XX XX XX XX

snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.4.3.1.2

SNMPv2-SMI::mib-2.17.4.3.1.2.0.2.253.255.213.15 = INTEGER: 22

# Notice the 22 :)

snmpwalk -v 2c -c xxx 192.168.x.x 1.3.6.1.2.1.17.1.4.1.2.22

SNMPv2-SMI::mib-2.17.1.4.1.2.22 = INTEGER: 10122
like image 37
raz3r Avatar answered Oct 12 '22 09:10

raz3r