Linux +哪个工具可以帮助识别连接到Cisco交换机中哪个端口的Linux机器中的哪个eth

我有一个超过50个不同的Linux机器(BLADE机器)具有以下IP范围的系统

165.23.1.21-165.23.1.64 ( each Linux machine have 4 eth - eth1,2,3,4) 

系统通过LANS电缆连接到4个思科交换机

我的目标是validationLinux机器中的每个eth是否连接到交换机的哪个端口

例如

./my_tool

  machine1 results linux_machine1_eth0 connected to switch_1_port_15 linux_machine1_eth1 connected to switch_2_port_15 linux_machine1_eth2 connected to switch_1_port_16 linux_machine1_eth3 connected to switch_2_port_16 machine2 results linux_machine2_eth0 connected to switch_1_port_22 linux_machine2_eth1 connected to switch_4_port_7 linux_machine2_eth2 connected to switch_1_port_23 linux_machine2_eth3 connected to switch_4_port_8 . . 

我的问题是哪个工具可以帮助确定哪台Linux机器连接到交换机的哪个端口?

  remark - 1. the tool can be also script that runs on the Linux machines 2. we have access to the switch by telnet 

我想你将不得不去每个交换机并发出命令

 show mac-address-table 

并记下所提供的信息。 然后去每台linux机器上做类似的事情

 echo $(hostname); ifconfig eth0 | grep HWaddr | awk '{print " "$1,$5}' 

现在你有两个名单来匹配。

如果在交换机上启用CDP,则可以尝试cdpr 。 这是一个简单的程序,你在服务器上运行,并听取CDP宣布。

 petrus@seth:~$ sudo cdpr cdpr - Cisco Discovery Protocol Reporter Version 2.2.1 Copyright (c) 2002-2006 - MonkeyMental.com 1. eth0 (No description available) 2. wlan0 (No description available) 3. virbr0 (No description available) <snip> 12. lo (No description available) Enter the interface number (1-12):1 Using Device: eth0 Waiting for CDP advertisement: (default config is to transmit CDP packets every 60 seconds) Device ID value: switch01 Addresses value: 192.168.12.15 Port ID value: 0/15 

cdpr也可以使用GET请求将详细信息上传到Web服务器。

你可以使用Net::Telnet::CiscoNet::OpenSSH来编写perl脚本来实现这个function。 如果我今天有一段时间,我会在这里提供一个。

UPDATE

正如在评论中提问者所问:如果你想通过SNMP获取信息,那么在cisco库中有一个非常好的文档: http : //www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a00801c9199的.shtml

简而言之:你需要合并五个snmpwalk的输出(你可以在这里使用crumpy

 snmpwalk -c public crumpy .1.3.6.1.4.1.9.9.46.1.3.1.1.2 # get vlan states snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.4.3.1.1 # get mac table snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.4.3.1.2 # get the switchport numbers for the vlans (here Vlan1) snmpwalk -c public@1 crumpy .1.3.6.1.2.1.17.1.4.1.2 # switchport to if number snmpwalk -c public@1 crumpy .1.3.6.1.2.1.31.1.1.1.1 # get the interface names 

从文档:

 6. Link a MAC address to the port on which the address was learned. * From Step 1, the MAC address is: 17.4.3.1.1.0.0.12.7.172.8 = Hex: 00 00 0C 07 AC 08 * From Step 2, the bridge port tells that the MAC address belongs to bridge port number 13: 17.4.3.1.2.0.0.12.7.172.8 = 13 * From Step 3, the bridge port number 13 has ifIndex number 2: 17.1.4.1.2.13 = 2 * From Step 4, the ifIndex 2 corresponds to port Fast Ethernet 0/1: ifMIB.ifMIBObjects.ifXTable.ifXEntry.ifName.2 = Fa0/1 

OpenNMS通过Linkdfunction做到了这一点,通过SNMP,CDP和路由信息自动发现节点之间的链接。 它也允许你创build拓扑图 。

交换机的链接页面如下所示: 在这里输入图像说明

虽然节点的链接页面如下所示: 在这里输入图像说明

除此之外,您在交换机上停留了一些show mac address例程。