2

我在一个数据中心工作,我正在编写一个 php 工具来映射我们所有的设备,并且可以告诉我们是否有什么是收费的。

它首先从两个内核中提取大量 mac 及其 ips 到一个临时表中。然后,它遍历所有机架*并尝试查找该 mac 属于哪个端口。由于没有黄金命令(提示灯泡在你的头上),我必须:

  1. 创建一个多数组,其中端口为键,ifindex 为值。
  2. 将 ifindex 替换为网桥 ID。
  3. 用 mac 哈希替换网桥 ID。
  4. 用实际的 mac 替换 mac 哈希

最后,它使用 mac、ips 和端口并填充主表。

问题是第一步。1.3.6.1.2.1.31.1.1.1.1 适用于大多数开关,但少数代工厂不工作。1.3.6.1.4.1.1991.1.1.3.3.1.1.38 有点接近我正在寻找的东西,但我并不完全舒服,这就是我正在寻找的东西。我能够在代工厂 > 产品 > 注册下找到特定的设备型号,但该文件夹下没有任何 MIB。所以我的问题是:

  1. 是否有返回端口和 mac 的代工厂特定字符串?ifindexes 也可以。
  2. 如何使用特定于设备的 MIB (enterprises.foundry.products.registration.snFWSXFamily)?

这方面的任何方向都会很棒。-贾斯汀

*= 机架型号:cisco 2900xl,代工厂 FI4802 + 变体

4

3 回答 3

2

您可以这样做(在 HP Procurve 上测试):

从您的 linux 服务器:

$ snmpwalk -v 1 -c 公共 xxx.xxx.xxx.xxx 1.3.6.1.2.1.17.4.3.1.2 | grep“整数:11”

(端口号 11)

将返回 :

SNMPv2-SMI::mib-2.17.4.3.1.2.44.118.138.64.143.95 = 整数:11 SNMPv2-SMI::mib-2.17.4.3.1.2.56.170.60.108.174.57 = 整数:11 SNMPv2-SMI::mib -2.17.4.3.1.2.104.181.153.172.54.237 = 整数:11 SNMPv2-SMI::mib-2.17.4.3.1.2.120.172.192.143.226.236 = 整数:11 SNMPv2-SMI::mib-2.17.4.3.1.2 .124.195.161.20.109.76 = 整数:11 SNMPv2-SMI::mib-2.17.4.3.1.2。152.75.225.59.127.180 = 整数:11

然后您可以执行此操作来查找连接的 Mac 地址:

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

返回mac地址:

SNMPv2-SMI::mib-2.17.4.3.1.1.152.75.225.59.127.180 = 十六进制字符串:98 4B E1 3B 7F B4

您可以制作一个 script.sh 来执行此操作...

于 2013-04-24T15:49:03.920 回答
0

当我需要从我的交换机中发现 MAC 和其他一些信息时,我使用了“snmpwalk”和“snmpbulkwalk”命令来检查它们的 SNMP 数据内容

例如:

snmpbulkwalk -v2c 192.168.30.40 -c public 1.3.6.1.2.1.31.1.1.1.1

输出:

IF-MIB::ifName.1 = STRING: Gi0/1
IF-MIB::ifName.2 = STRING: Gi0/2
IF-MIB::ifName.3 = STRING: Gi0/3
IF-MIB::ifName.4 = STRING: Gi0/4
IF-MIB::ifName.5 = STRING: Gi0/5
IF-MIB::ifName.6 = STRING: Gi0/6
IF-MIB::ifName.7 = STRING: Gi0/7
IF-MIB::ifName.8 = STRING: Gi0/8
IF-MIB::ifName.9 = STRING: Gi0/9
IF-MIB::ifName.10 = STRING: Gi0/10
IF-MIB::ifName.11 = STRING: Gi0/11
IF-MIB::ifName.12 = STRING: Gi0/12
IF-MIB::ifName.13 = STRING: Nu0
IF-MIB::ifName.14 = STRING: Vl1
IF-MIB::ifName.15 = STRING: Vl2
IF-MIB::ifName.16 = STRING: Vl416

snmpbulkwalk -v2c 192.168.30.40 -c public 1.3.6.1.2

输出大量信息,您可以在其中查找您最喜欢的 MAC 或任何东西

于 2010-05-28T18:13:20.627 回答
0

如果您想从 Windows Server 以编程方式执行此操作,您可以使用 SnmpSharpNet 库来完成同样的事情。这是一个示例,它将使用 OID 1.3.6.1.2.1.17.7.1.2.2.1.2.1 创建特定戴尔交换机上所有 MAC 地址和端口的列表

    using SnmpSharpNet;

    List<KeyValuePair<string, string>> portList = new List<KeyValuePair<string, string>>();

    IPAddress ip = IPAddress.Parse("192.168.0.2");
    SnmpWalk(ip, "snmpcommunity", "1.3.6.1.2.1.17.7.1.2.2.1.2.1", "1");

    //SNMPWALK the ports on a switch or stack of switches. Ports will be labeled SwitchNum/Stack Number/Port Numbers.
    private void SnmpWalk(IPAddress ip, string snmpCommunity, string oid, string switchNum)
    {
        UdpTarget target = new UdpTarget(ip);

        // SNMP community name
        OctetString community = new OctetString(snmpCommunity);
        // Define agent parameters class
        AgentParameters param = new AgentParameters(community);
        // Set SNMP version to 1
        param.Version = SnmpVersion.Ver1;


        // Define Oid that is the root of the MIB tree you wish to retrieve
        Oid rootOid = new Oid(oid);

        // This Oid represents last Oid returned by the SNMP agent
        Oid lastOid = (Oid)rootOid.Clone();

        // Pdu class used for all requests
        Pdu pdu = new Pdu(PduType.GetNext);

        // Loop through results
        while (lastOid != null)
        {
            // When Pdu class is first constructed, RequestId is set to a random value
            // that needs to be incremented on subsequent requests made using the
            // same instance of the Pdu class.
            if (pdu.RequestId != 0)
            {
                pdu.RequestId += 1;
            }
            // Clear Oids from the Pdu class.
            pdu.VbList.Clear();
            // Initialize request PDU with the last retrieved Oid
            pdu.VbList.Add(lastOid);
            // Make SNMP request
            SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
            // You should catch exceptions in the Request if using in real application.

            // If result is null then agent didn't reply or we couldn't parse the reply.
            if (result != null)
            {
                // ErrorStatus other then 0 is an error returned by 
                // the Agent - see SnmpConstants for error definitions
                if (result.Pdu.ErrorStatus != 0)
                {
                    // agent reported an error with the request
                    Console.WriteLine("Error in SNMP reply. Error {0} index {1}",
                        result.Pdu.ErrorStatus,
                        result.Pdu.ErrorIndex);
                    lastOid = null;
                    break;
                }
                else
                {
                    // Walk through returned variable bindings
                    foreach (Vb v in result.Pdu.VbList)
                    {
                        // Check that retrieved Oid is "child" of the root OID
                        if (rootOid.IsRootOf(v.Oid))
                        {
                            //Convert OID to MAC
                            string[] macs = v.Oid.ToString().Split('.');
                            string mac = "";
                            int counter = 0;
                            foreach (string chunk in macs)
                            {
                                if (counter >= macs.Length - 6)
                                {
                                    mac += string.Format("{0:X2}", int.Parse(chunk));
                                }
                                counter += 1;
                            }

                            //Assumes a 48 port switch (52 actual). You need to know these values to correctly iterate through a stack of switches.
                            int dellSwitch = 1 + int.Parse(v.Value.ToString()) / 52;
                            int port = int.Parse(v.Value.ToString()) - (52 * (dellSwitch - 1));
                            KeyValuePair<string, string> Port = new KeyValuePair<string, string>(mac, switchNum + "/" + dellSwitch.ToString() + "/" + port.ToString());
                            portList.Add(Port);

                            //Exit Loop
                            lastOid = v.Oid;
                        }
                        else
                        {
                            //End of the requested MIB tree. Set lastOid to null and exit loop
                            lastOid = null;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("No response received from SNMP agent.");
            }
        }
        target.Close();
    }

有一个使用此示例的完整项目将这里信息解析回主机名

于 2015-11-24T22:09:57.227 回答