SNMP 陷阱侦听器抛出异常 nullReferenceException
我正在使用C#中的SNMP库创建SNMP陷阱侦听器。我使用以下代码接收陷阱,
try
{
lst = new Listener();
lst.AddBinding(new IPEndPoint(IPAddress.Any, 162));
lst.MessageReceived += Listener_MessageReceived;
lst.StartAsync();
}
catch (Exception ex)
{
}
private static void Listener_MessageReceived(object sender, MessageReceivedEventArgs e)
{
// SNMP trap recived Here.
File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Version + "\n");
File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Scope.Pdu.Variables[4].Data.ToString() + "\n");
}
然后将其作为服务运行,然后使用陷阱模拟器发送TRPA。以下是我在日志文件中获得的输出。
- 处理:输入。 handlemessage system.collections.generic.list`1 [lexm.sharpsnmplib.messaging.isnmpmessage]版本:v2*
I am creating an SNMP Trap Listener using SNMP Library in c#. I used the following code to receive traps
try
{
lst = new Listener();
lst.AddBinding(new IPEndPoint(IPAddress.Any, 162));
lst.MessageReceived += Listener_MessageReceived;
lst.StartAsync();
}
catch (Exception ex)
{
}
private static void Listener_MessageReceived(object sender, MessageReceivedEventArgs e)
{
// SNMP trap recived Here.
File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Version + "\n");
File.AppendAllText("c:/temp/servicelog.log", "Version :" + e.Message.Scope.Pdu.Variables[4].Data.ToString() + "\n");
}
I run this as a service and then I send trpas using Trap Simulator. The following is the output I got in log file.
- HandleMessage :Enter.
HandleMessage System.Collections.Generic.List`1[Lextm.SharpSnmpLib.Messaging.ISnmpMessage]Version :V2*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论