예제 #1
0
        public void Walkv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, WalkMode walkMode, SNMPOptions options)
        {
            Task.Run(() =>
            {
                try
                {
                    IList <Variable> results = new List <Variable>();

                    Messenger.Walk(version == SNMPVersion.v1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, options.Port), new OctetString(community), new ObjectIdentifier(oid), results, options.Timeout, walkMode);

                    foreach (Variable result in results)
                    {
                        OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
                    }

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
예제 #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
                {
                    IPEndPoint ipEndpoint = new IPEndPoint(ipAddress, options.Port);

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

                    IPrivacyProvider privacy;

                    if (security == SNMPv3Security.authPriv)
                    {
                        privacy = GetPrivacy(authProvider, auth, privProvider, priv);
                    }
                    else if (security == SNMPv3Security.authNoPriv)
                    {
                        privacy = GetPrivacy(authProvider, auth);
                    }
                    else // noAuthNoPriv
                    {
                        privacy = GetPrivacy();
                    }

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

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
예제 #3
0
        public void Walkv3Async(IPAddress ipAddress, string oid, SNMPv3Security security, string username, SNMPv3AuthenticationProvider authProvider, string auth, SNMPv3PrivacyProvider privProvider, string priv, WalkMode walkMode, SNMPOptions options)
        {
            Task.Run(() =>
            {
                try
                {
                    IPEndPoint ipEndpoint = new IPEndPoint(ipAddress, options.Port);

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

                    IPrivacyProvider privacy;

                    if (security == SNMPv3Security.authPriv)
                    {
                        privacy = GetPrivacy(authProvider, auth, privProvider, priv);
                    }
                    else if (security == SNMPv3Security.authNoPriv)
                    {
                        privacy = GetPrivacy(authProvider, auth);
                    }
                    else // noAuthNoPriv
                    {
                        privacy = GetPrivacy();
                    }

                    List <Variable> results = new List <Variable>();

                    Messenger.BulkWalk(VersionCode.V3, ipEndpoint, new OctetString(username), new ObjectIdentifier(oid), results, options.Timeout, 10, walkMode, privacy, report);

                    foreach (Variable result in results)
                    {
                        OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
                    }

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
예제 #4
0
        public void Setv1v2cAsync(SNMPVersion version, IPAddress ipAddress, string communtiy, string oid, string data, SNMPOptions options)
        {
            Task.Run(() =>
            {
                try
                {
                    Messenger.Set(version == SNMPVersion.v1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, options.Port), new OctetString(communtiy), new List <Variable> {
                        new Variable(new ObjectIdentifier(oid), new OctetString(data))
                    }, options.Timeout);

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
예제 #5
0
        public void GetV1V2CAsync(SNMPVersion version, IPAddress ipAddress, string community, string oid, SNMPOptions options)
        {
            Task.Run(() =>
            {
                try
                {
                    foreach (var result in Messenger.Get(version == SNMPVersion.V1 ? VersionCode.V1 : VersionCode.V2, new IPEndPoint(ipAddress, options.Port), new OctetString(community), new List <Variable> {
                        new Variable(new ObjectIdentifier(oid))
                    }, options.Timeout))
                    {
                        OnReceived(new SNMPReceivedArgs(result.Id, result.Data));
                    }

                    OnComplete();
                }
                catch (Lextm.SharpSnmpLib.Messaging.TimeoutException)
                {
                    OnTimeout();
                }
                catch (ErrorException)
                {
                    OnError();
                }
            });
        }
예제 #6
0
        public void Getv3Async(IPAddress ipAddress, string oid, SNMPV3Security security, string username, SNMPV3AuthenticationProvider authProvider, string auth, SNMPV3PrivacyProvider privProvider, string priv, 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 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(options.Timeout, ipEndpoint);

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

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

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