我遇到了问题,运行SNMP命令与snmpsharpnet库。我正在研究一个示例,它们为运行一个简单的get提供了一个示例,但是它出错了。我已经测试了在这个盒子上运行这个OID,并且我能够得到一个响应,但是我不能用这个程序
我的代码如下所示:
try{
SimpleSnmp snmp = new SimpleSnmp(HOST, COMMUNITY);
Pdu pdu = new Pdu();
//pdu.Type = SnmpConstants.GETNEXT; // type GETNEXT
pdu.VbList.Add(".1.3.6.1.2.1.1.1.0");
Dictionary<Oid, AsnType> result = snmp.Get(SnmpVersion.Ver2,pdu); //.GetNext(pdu);
if (result == null){
Console.WriteLine("Request failed.");
}else{
foreach (KeyValuePair<Oid, AsnType> entry in result)
{
Console.WriteLine("{0} = {1}: {2}", entry.Key.ToString(), SnmpConstants.GetTypeName(entry.Value.Type),
entry.Value.ToString());
}
}
}catch (Exception ex){
Console.WriteLine("Error: " + ex + Environment.NewLine + "-------------------------------------------------------");
}我收到的错误如下所示:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'SnmpSharpNet.SnmpException' occurred in SnmpSharpNet.dll
The thread 0xeec has exited with code 259 (0x103).提前感谢!
发布于 2014-06-09 07:57:30
您没有收到远程主机对您发送的请求的响应。这就是套接字异常的原因。其中有3个,因为SimpleSnmp类的默认设置是进行3次尝试发送和接收来自服务器的响应。
如果将Retry对象的snmp属性设置为比2更高的数目,它将发送更多的请求并侦听更多的响应,从而产生更多的这些异常。
snmp的标准行为是不对(a)格式错误或(b)没有正确的社区字符串的请求生成任何响应。
如果您已经展示了运行这段代码的结果控制台输出是什么,我很肯定它会说Request failed.
https://stackoverflow.com/questions/24090542
复制相似问题