使用snmptrapd示例我能够轻松接收v1陷阱和v2陷阱/通知。但是,使用v3我无法接收陷阱。我使用AES128和SHA1进行隐私和身份验证。
当我“wireshark”端口162时,我看到来自我试图接收陷阱的设备的“encryptedPDU:privKey unknown”。如果有帮助,它正在使用NET-SNMP。
我能够使用SharpSNMP实现应用程序的获取和设置没有问题。我在这里缺少什么?
以下代码段:
注意:engine.Start()是从实例化类中调用的。
registry = new UserRegistry();
var authProvider = new SHA1AuthenticationProvider(new OctetString("authsecret"));
var privacyProvider = new AESPrivacyProvider(new OctetString("privsecret"), authProvider);
registry.Add(new OctetString("informuser"), privacyProvider);
registry.Add(new OctetString("trapuser"), privacyProvider);
TrapV1Handler = new TrapV1MessageHandler();
TrapV1Handler.MessageReceived += WatcherTrapV1Received;
v1Mapping = new HandlerMapping("v1", "TRAPV1", TrapV1Handler);
TrapV2Handler = new TrapV2MessageHandler();
TrapV2Handler.MessageReceived += WatcherTrapV2Received;
v2Mapping = new HandlerMapping("v2,v3", "TRAPV2", TrapV2Handler);
InformHandler = new InformRequestMessageHandler();
InformHandler.MessageReceived += WatcherInformRequestReceived;
informMapping = new HandlerMapping("v2,v3", "INFORM", InformHandler);
store = new ObjectStore();
var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public"));
var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public"));
var v3 = new Version3MembershipProvider();
var membership = new ComposedMembershipProvider(new IMembershipProvider[] {v1, v2, v3});
var handlerFactory = new MessageHandlerFactory(new[] {v1Mapping, v2Mapping, informMapping});
var pipelineFactory = new SnmpApplicationFactory(store, membership, handlerFactory);
engine = new SnmpEngine(pipelineFactory, new Listener { Users = registry }, new EngineGroup());
engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, 162));
engine.ExceptionRaised += this.DoSomething;
}
private void DoSomething(object sender, ExceptionRaisedEventArgs args)
{
// never gets here
}
private void WatcherInformRequestReceived(object sender, InformRequestMessageReceivedEventArgs e)
{
// or here for v3 (works fine for v2)
}
private void WatcherTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e)
{
// or here for v3 (works fine for v2)
}
private void WatcherTrapV1Received(object sender, TrapV1MessageReceivedEventArgs e)
{
// works fine
}