我在使用 snmpsharpnet 库运行 SNMP 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).
提前致谢!