我正在测试 SharpSNMP 库并使用示例进行了一些操作,该库很棒,但缺少一些文档。
我的问题是如何改变我正在聆听陷阱的社区,因为示例中的任何内容都没有让我理解。
if (args.Length != 0)
{
return;
}
Container = new UnityContainer().LoadConfiguration("snmptrapd");
var users = Container.Resolve<UserRegistry>();
users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair);
users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication"))));
users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"),
new MD5AuthenticationProvider(new OctetString("authentication"))));
var trapv1 = Container.Resolve<TrapV1MessageHandler>("TrapV1Handler");
trapv1.MessageReceived += WatcherTrapV1Received;
var trapv2 = Container.Resolve<TrapV2MessageHandler>("TrapV2Handler");
trapv2.MessageReceived += WatcherTrapV2Received;
var inform = Container.Resolve<InformRequestMessageHandler>("InformHandler");
inform.MessageReceived += WatcherInformRequestReceived;
using(var engine = Container.Resolve<SnmpEngine>())
{
engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, 162));
engine.Start();
Console.WriteLine("#SNMP is available at http://sharpsnmplib.codeplex.com");
Console.WriteLine("Press any key to stop . . . ");
Console.Read();
engine.Stop();
}