0

我正在尝试使用 SnmpSharpNet 跨不同网络监控多个 SNMP 代理(时间标记)。下面的代码适用于单个 IP 地址,但是当我尝试连接到第二个 IP 地址时,代码失败,我正在尝试异步运行,但似乎 SnmpSharpNet 不允许我从多个 IP 地址接收数据代理人。

这是解决这个问题的正确方法吗?有没有比 SmnpSharpNet 更好的替代品?

community = new OctetString("public");
// Define agent parameters class
param = new AgentParameters(community);
// Set SNMP version to 1 (or 2)
param.Version = SnmpVersion.Ver1;

for (int i = 0; i < sendsqldatalist.Count(); i++)
{
    agent = new IpAddress(sendsqldatalist[i].ip);
    target = new UdpTarget((IPAddress)agent, 161, 2000, 1);

    // Make SNMP request        
    resultlist.Add(result = (SnmpV1Packet)target.Request(pdu, param));

    // If result is null then agent didn't reply or we couldn't parse the reply.r
    if (resultlist[i] != null)
    {
        // ErrorStatus other then 0 is an error returned by 
        // the Agent - see SnmpConstants for error definitions
        if (resultlist[i].Pdu.ErrorStatus != 0)
        {
            Console.WriteLine("error on - " + sendsqldatalist[i].oid + "    " + sendsqldatalist[i].ip);
            // agent reported an error with the request
            //- Error status found here http://www.docs.snmpsharpnet.com/docs-0-9-1/
            MessageBox.Show("Error in SNMP reply from " + target.Address.ToString() + Environment.NewLine + "Error status " + result.Pdu.ErrorStatus.GetType() + Environment.NewLine + "Error Index " + result.Pdu.ErrorIndex.ToString(), "WARNING!");
        }
        else
        {
            Console.WriteLine("ConnectSNMP() CONNECTED - " + sendsqldatalist[i].oid + "  -  " + sendsqldatalist[i].ip);                           
        }                    
    }
}

提前致谢!

4

0 回答 0