0

我正在测试 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();
        }
4

1 回答 1

0

用户被添加到用户注册表中,因此如果 SNMP v3 消息(TRAP v2 或 INFORM),陷阱代理可以正确处理它。

如果在您的场景中您需要使用其他用户,您可以手动创建它们然后插入到注册表中。

于 2013-01-03T12:51:12.257 回答