【发布时间】:2014-06-06 21:00:57
【问题描述】:
我在使用 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).
提前致谢!
【问题讨论】:
-
您可能想提及您如何从相关系统(例如 snmpget)中获得正确结果。确保主机和社区字符串在工作示例和提供的代码匹配之间匹配。检查
SimpleSnmp实例的Valid属性。默认的pdu.Type是GET,但为了安全起见,你应该设置它。 -
可以添加程序的输出吗?
Console.WriteLine应该在控制台中写下错误的描述。 -
sharp-snmp 标签用于#SNMP 库。不要将它用于 snmpsharpnet,因为它们是完全不同的东西。
-
我得到的输出是上面原始帖子中显示的内容,在我的终端窗口中我得到“请求失败”。留言
标签: c# snmp snmpsharpnet