SNMPsharpnet SnmpNetworkException:'网络错误:对等重置连接。'

时间:2019-02-14 15:52:32

标签: connection snmpsharpnet

我是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");
 }

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

我也遇到了同样的问题,解决方案是在Windows上安装SNMP Service,并且应该可以正常工作

此链接应该可以帮助您https://support.microsoft.com/en-us/help/324263/how-to-configure-the-simple-network-management-protocol-snmp-service-i