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?


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 (. 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 .
SNMPv2-SMI::mib- = Hex-STRING: 00 14 7C 3E C6 A1

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

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

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

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

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

>snmpwalk -v 2c -c public myswitch .
IF-MIB::ifName.200 = STRING: 4/20

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.

  • 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 2 '10 at 2:33

PHP code that will give you what you want:

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

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

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, ".".$_dot1dTpFdbAddress_key_unique['0']);

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

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

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

        $mac = str_replace(" ", ":", strtolower($_dot1dTpFdbAddress_value_unique['0']));
        $mac = ereg_replace("(^:|:$)","", $mac);
        $_mac[$mac] = $_ifName['1'];
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.