我是C#的初学者,我正在尝试为我的一些设备创建一个读取snmp的工具。通常,当我无法到达IP地址或IP地址不使用相同的OID时,系统正常工作。
我想要实现的是:如果设备无法到达:跳到下一个设备。如果设备没有正确的OID :跳到下一个OID。
目前,当发生这种情况时,我有一个类似于此的错误: error SnmpSharpNet.SnmpNetworkException:‘网络错误:由对等者重置连接’。
由 SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu,param)引起;
我的代码示例
//Start
UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
Pdu pdu = new Pdu(PduType.Get);
pdu.VbList.Add(".1.3.6.1.4.1.1552.21.3.1.1.5.1.0");
pdu.VbList.Add(".1.3.6.1.4.1.1552.21.3.1.1.5.2.0");
pdu.VbList.Add(".1.3.6.1.4.1.1552.21.3.1.1.5.7.0");
pdu.VbList.Add(".1.3.6.1.4.1.1552.21.3.1.1.5.8.0");
// Make SNMP request
SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
// If result is null then agent didn't reply or we couldn't parse the reply.
if (result != null)
{
if (result.Pdu.ErrorStatus != 0)
{
// agent reported an error with the request
MessageBox.Show("Error");
}谢谢你的帮助
发布于 2019-09-29 19:47:09
我也遇到过同样的问题,解决方案是在您的窗口上安装SNMP服务,它应该可以正常工作。
https://stackoverflow.com/questions/54694308
复制相似问题