Exemplo n.º 1
0
        public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, SecureString auth, SNMPV3PrivacyProvider privProvider, SecureString priv)
        {
            Task.Run(() =>
            {
                try
                {
                    var ipEndpoint = new IPEndPoint(ipAddress, Port);

                    // Discovery
                    var discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
                    var report    = discovery.GetResponse(Timeout, ipEndpoint);

                    IPrivacyProvider privacy;

                    switch (security)
                    {
                    case SNMPV3Security.AuthPriv:
                        privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth), privProvider, SecureStringHelper.ConvertToString(priv));
                        break;

                    // noAuthNoPriv
                    case SNMPV3Security.AuthNoPriv:
                        privacy = GetPrivacy(authProvider, SecureStringHelper.ConvertToString(auth));
                        break;

                    default:
                        privacy = GetPrivacy();
                        break;
                    }

                    var request = new GetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(username), new List <Variable> {
                        new Variable(new ObjectIdentifier(oid))
                    }, privacy, Messenger.MaxMessageSize, report);
                    var reply = request.GetResponse(Timeout, ipEndpoint);

                    var result = reply.Pdu().Variables[0];

                    OnReceived(new SNMPReceivedArgs(result.Id, result.Data));

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeoutReached();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
Exemplo n.º 2
0
        public void SetV3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, string auth, SNMPV3PrivacyProvider privProvider, string priv, string data, SNMPOptions options)
        {
            Task.Run(() =>
            {
                try
                {
                    var ipEndpoint = new IPEndPoint(ipAddress, options.Port);

                    // Discovery
                    var discovery = Messenger.GetNextDiscovery(SnmpType.GetRequestPdu);
                    var report    = discovery.GetResponse(options.Timeout, ipEndpoint);

                    IPrivacyProvider privacy;

                    switch (security)
                    {
                    case SNMPV3Security.AuthPriv:
                        privacy = GetPrivacy(authProvider, auth, privProvider, priv);
                        break;

                    // noAuthNoPriv
                    case SNMPV3Security.AuthNoPriv:
                        privacy = GetPrivacy(authProvider, auth);
                        break;

                    default:
                        privacy = GetPrivacy();
                        break;
                    }

                    var request = new SetRequestMessage(VersionCode.V3, Messenger.NextMessageId, Messenger.NextRequestId, new OctetString(username), OctetString.Empty, new List <Variable> {
                        new Variable(new ObjectIdentifier(oid), new OctetString(data))
                    }, privacy, Messenger.MaxMessageSize, report);
                    var reply = request.GetResponse(options.Timeout, ipEndpoint);

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }