2

I have a Dell 6248 switch. I connect some of my servers to it and want to know which server nic connected to which switch port. I try using snmpwalk to get this information, but I just can get mac/ip mapping of my server nic from switch, I still can't get which switch port it connect.

I try a tool named Managed Switch Port Mapping tool, it can show which switch port is connected to which nic/ip. I use WireShare to get all snmp packets but still can't find what's the snmp oid to get this information.

Anyone knows how to get this?

Scott Pack
  • 14,907
  • 10
  • 53
  • 83
Brad
  • 21
  • 1
  • 2

3 Answers3

4

You have to do a little bit of tracking through BRIDGE-MIB and IF-MIB.

(Caveat: I don't have your specific switch model to test on, but these are standard MIBs, so this should work.)

Use dot1dTpFdbAddress (.1.3.6.1.2.1.17.4.3.1.1) from BRIDGE-MIB to find the MAC addresses (example shows a single line of snmpwalk output for clarity, you'll probably get several rows returned):

>snmpwalk -v 2c -c public myswitch .1.3.6.1.2.1.17.4.3.1.1
SNMPv2-SMI::mib-2.17.4.3.1.1.0.20.124.62.198.161 = Hex-STRING: 00 14 7C 3E C6 A1

Take those numbers that follow the base OID (looking at the example, I'm talking about 0.20.124.62.198.161). Use them to find the value of dot1dTpFdbPort (.1.3.6.1.2.1.17.4.3.1.2), also from BRIDGE-MIB:

>snmpwalk -v 2c -c public myswitch .1.3.6.1.2.1.17.4.3.1.2
SNMPv2-SMI::mib-2.17.4.3.1.2.0.20.124.62.198.161 = INTEGER: 794

Take the integer values from dot1dTpFdbPort (794 in the example) and use them to find the value of dot1dBasePortIfIndex (.1.3.6.1.2.1.17.1.4.1.2), again from BRIDGE-MIB:

>snmpwalk -v 2c -c public myswitch .1.3.6.1.2.1.17.1.4.1.2
SNMPv2-SMI::mib-2.17.1.4.1.2.794 = INTEGER: 200

That value is your ifIndex (200 in the example). Use that to pull a human-friendly value out of ifName (.1.3.6.1.2.1.31.1.1.1.1), from IF-MIB:

>snmpwalk -v 2c -c public myswitch .1.3.6.1.2.1.31.1.1.1.1
IF-MIB::ifName.200 = STRING: 4/20
gorthx
  • 176
  • 2
0

If your goal is to find out which hosts are connected to which ports, why not log in to the switch management interface (web or cli) and look at the address table, which will show you which MAC addresses are connected to which ports.

joeqwerty
  • 109,901
  • 6
  • 81
  • 172
  • The problem is I got this request from our client to provide a program to show these information. They will have several switch connected together and they want to know port connection information as well as bandwidth. I can't ask client to use cli to log in each switch one by one to get these information – Brad Dec 02 '10 at 02:33
0

PHP code that will give you what you want:

<?php
$_snmp_ip = <ip>;
$_snmp_com = <community>;

$_dot1dTpFdbAddress = snmp2_real_walk($_snmp_ip, $_snmp_com, ".1.3.6.1.2.1.17.4.3.1.1.0");

foreach($_dot1dTpFdbAddress  as $_dot1dTpFdbAddress_key => $_dot1dTpFdbAddress_value)
{
        preg_match("/(\.[\d]*){6}$/i", $_dot1dTpFdbAddress_key, $_dot1dTpFdbAddress_key_unique);
        preg_match("/([0-9A-F ]*){6}$/i", $_dot1dTpFdbAddress_value, $_dot1dTpFdbAddress_value_unique);
        $_dot1dTpFdbPort = snmp2_get($_snmp_ip, $_snmp_com, ".1.3.6.1.2.1.17.4.3.1.2".$_dot1dTpFdbAddress_key_unique['0']);

        preg_match("/[\d]*$/i", $_dot1dTpFdbPort, $_dot1dTpFdbPort);
        $_dot1dBasePortIfIndex = snmp2_get($_snmp_ip, $_snmp_com, ".1.3.6.1.2.1.17.1.4.1.2.".$_dot1dTpFdbPort['0']);

        preg_match("/[\d]*$/i", $_dot1dBasePortIfIndex, $_dot1dBasePortIfIndex);
        $_ifName = snmp2_get($_snmp_ip, $_snmp_com, ".1.3.6.1.2.1.31.1.1.1.1.".$_dot1dBasePortIfIndex['0']);

        preg_match("/\"([^\"]*)\"$/i", $_ifName, $_ifName);

        $mac = str_replace(" ", ":", strtolower($_dot1dTpFdbAddress_value_unique['0']));
        $mac = ereg_replace("(^:|:$)","", $mac);
        $_mac[$mac] = $_ifName['1'];
}
print_r($_mac);
?>
  • 1
    This is making a bunch of assumptions about whether the OP has the infrastructure or knowledge to make use of this. Your answer would be more useful if it included information about what the OP will need to set up in order to use the code you give. – dunxd Mar 19 '13 at 11:21