【发布时间】:2019-02-14 15:52:31
【问题描述】:
我是 C# 的初学者,我正在尝试创建一个工具来读取我的某些设备的 snmp OID。 一般来说,系统工作正常,除了当我无法到达 IP 地址或 IP 地址未使用相同的 OID 时。
我想要实现的是:如果设备无法访问:跳到下一个。如果设备没有正确的 OID:跳到下一个。
目前,当它发生时,我有一个像这样的错误: 错误 SnmpSharpNet.SnmpNetworkException: '网络错误:连接被对等方重置。'
由引起 SnmpV1Packet 结果 = (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");
}
感谢您的帮助
【问题讨论】: