Example #1
0
 /// <summary>
 /// Get instance of authentication protocol.
 /// </summary>
 /// <param name="authProtocol">Authentication protocol code. Available codes are <see cref="AuthenticationDigests.MD5"/>,
 /// <see cref="AuthenticationDigests.SHA1"/> or <see cref="AuthenticationDigests.None"/></param>
 /// <returns>Instance of the authentication protocol or null if unrecognized authentication protocol or value
 /// <see cref="AuthenticationDigests.None"/> is passed.</returns>
 public static IAuthenticationDigest GetInstance(AuthenticationDigests authProtocol)
 {
     if (authProtocol == AuthenticationDigests.MD5)
         return new AuthenticationMD5();
     else if (authProtocol == AuthenticationDigests.SHA1)
         return new AuthenticationSHA1();
     return null;
 }
Example #2
0
        /// <summary>
        /// Get instance of authentication protocol.
        /// </summary>
        /// <param name="authProtocol">Authentication protocol code. Available codes are <see cref="AuthenticationDigests.MD5"/>,
        /// <see cref="AuthenticationDigests.SHA1"/> or <see cref="AuthenticationDigests.None"/></param>
        /// <returns>Instance of the authentication protocol or null if unrecognized authentication protocol or value
        /// <see cref="AuthenticationDigests.None"/> is passed.</returns>
        public static IAuthenticationDigest GetInstance(AuthenticationDigests authProtocol)
        {
            if (authProtocol == AuthenticationDigests.MD5)
            {
                return(new AuthenticationMD5());
            }
            else if (authProtocol == AuthenticationDigests.SHA1)
            {
                return(new AuthenticationSHA1());
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Get instance of authentication protocol.
        /// </summary>
        /// <param name="authenticationProtocol">Authentication protocol code. Available codes are <see cref="AuthenticationDigests.MD5"/>,
        /// <see cref="AuthenticationDigests.SHA1"/> or <see cref="AuthenticationDigests.None"/></param>
        /// <returns>Instance of the authentication protocol or null if unrecognized authentication protocol or value
        /// <see cref="AuthenticationDigests.None"/> is passed.</returns>
        public static IAuthenticationDigest GetInstance(AuthenticationDigests authenticationProtocol)
        {
            switch (authenticationProtocol)
            {
            case AuthenticationDigests.MD5:
                return(new AuthenticationMD5());

            case AuthenticationDigests.SHA1:
                return(new AuthenticationSHA1());

            default:
                return(null);
            }
        }
        /// <summary>
        /// Reset USM object to default values. All OctetString and MutableByte members are reset to 0 length and
        /// privacy and authentication protocols are set to none.
        /// </summary>
        public void Reset()
        {
            _asnType        = 3;
            _engineId       = new OctetString();
            _engineBoots    = new Integer32();
            _engineTime     = new Integer32();
            _authentication = AuthenticationDigests.None;

            _securityName             = new OctetString();
            _authenticationSecret     = new MutableByte();
            _authenticationParameters = new OctetString();
            _privacySecret            = new MutableByte();
            _privacy           = PrivacyProtocols.None;
            _privacyParameters = new OctetString();
        }
Example #5
0
        /// <summary>Standard constructor.</summary>
        public UserSecurityModel()
        {
            Type           = 3;
            engineId       = new OctetString();
            engineBoots    = new Integer32();
            engineTime     = new Integer32();
            authentication = AuthenticationDigests.None;

            securityName             = new OctetString();
            authenticationSecret     = new MutableByte();
            authenticationParameters = new OctetString();
            privacySecret            = new MutableByte();
            privacy           = EPrivacyProtocols.None;
            privacyParameters = new OctetString();
        }
        /// <summary>
        /// Construct and send SNMP v3 authPriv Trap
        /// </summary>
        /// <param name="receiver">Trap receiver IP address</param>
        /// <param name="receiverPort">Trap receiver UDP port number</param>
        /// <param name="engineId">Sender SNMP engineId</param>
        /// <param name="senderEngineBoots">Sender SNMP engine boots</param>
        /// <param name="senderEngineTime">Sender SNMP engine time</param>
        /// <param name="senderUserName">Security (user) name</param>
        /// <param name="senderUpTime">Sender upTime</param>
        /// <param name="trapObjectID">Trap object ID</param>
        /// <param name="varList">Variable binding list</param>
        /// <param name="authDigest">Authentication digest. See <see cref="AuthenticationDigests"/> enumeration for
        /// available digests</param>
        /// <param name="authSecret">Authentication secret</param>
        /// <param name="privProtocol">Privacy protocol. See <see cref="PrivacyProtocols"/> enumeration for
        /// available privacy protocols.</param>
        /// <param name="privSecret">Privacy secret</param>
        public void SendV3Trap(IpAddress receiver, int receiverPort, byte[] engineId, Int32 senderEngineBoots,
                               Int32 senderEngineTime, string senderUserName, UInt32 senderUpTime, Oid trapObjectID, VbCollection varList,
                               AuthenticationDigests authDigest, byte[] authSecret, PrivacyProtocols privProtocol, byte[] privSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = PduType.V2Trap;
            packet.authPriv(ASCIIEncoding.UTF8.GetBytes(senderUserName), authSecret, authDigest, privSecret, privProtocol);
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Example #7
0
 /// <summary>
 /// Copy constructor. Initialize the class with the values of the parameter class values.
 /// </summary>
 /// <param name="second">Parameter class.</param>
 public SecureAgentParameters(SecureAgentParameters second)
     : this()
 {
     this._contextEngineId.Set(second.ContextEngineId);
     this._contextName.Set(second.ContextName);
     this._engineBoots.Value = second.EngineBoots.Value;
     this._engineId.Set(second.EngineId);
     this._engineTime.Value     = second.EngineTime.Value;
     this._engineTimeStamp      = second.EngineTimeStamp();
     this._maxMessageSize.Value = second.MaxMessageSize.Value;
     this._privacyProtocol      = second.Privacy;
     this._privacySecret.Set(second.PrivacySecret);
     this._authenticationProtocol = second.Authentication;
     this._authenticationSecret.Set(second.AuthenticationSecret);
     this._reportable = second.Reportable;
     this._securityName.Set(second.SecurityName);
 }
        /// <summary>
        /// Copy all relevant values from the SnmpV3Packet class. Do not use this class for
        /// updating the SNMP version 3 discovery process results because secret name, authentication
        /// and privacy values are updated as well which discovery process doesn't use.
        /// </summary>
        /// <param name="packet"><see cref="SnmpV3Packet"/> cast as <see cref="SnmpPacket"/></param>
        /// <exception cref="SnmpInvalidVersionException">Thrown when SNMP packet class other then version 3
        /// is passed as parameter</exception>
        public void UpdateValues(SnmpPacket packet)
        {
            if (packet is SnmpV3Packet pkt)
            {
                _authenticationProtocol = pkt.USM.Authentication;
                _privacyProtocol        = pkt.USM.Privacy;
                _authenticationSecret.Set(pkt.USM.AuthenticationSecret);
                _privacySecret.Set(pkt.USM.PrivacySecret);
                _securityName.Set(pkt.USM.SecurityName);
                if (pkt.MaxMessageSize < _maxMessageSize.Value)
                {
                    _maxMessageSize.Value = pkt.MaxMessageSize;
                }

                UpdateDiscoveryValues(pkt);
            }
            else
            {
                throw new SnmpInvalidVersionException("Invalid SNMP version.");
            }
        }
Example #9
0
        /// <summary>
        /// Reset the class. Initialize all member values to class defaults.
        /// </summary>
        public void Reset()
        {
            _engineId    = new OctetString();
            _engineBoots = new Integer32();
            _engineTime  = new Integer32();

            _engineTimeStamp = DateTime.MinValue;

            _privacyProtocol        = PrivacyProtocols.None;
            _authenticationProtocol = AuthenticationDigests.None;

            _privacySecret        = new MutableByte();
            _authenticationSecret = new MutableByte();

            _contextEngineId = new OctetString();
            _contextName     = new OctetString();
            _securityName    = new OctetString();

            // max message size is initialized to 64KB by default. It will be
            // to the smaller of the two values after discovery process
            _maxMessageSize = new Integer32(64 * 1024);

            _reportable = true;
        }
        /// <summary>
        /// Standard constructor.
        /// </summary>
        public UserSecurityModel()
        {
            _asnType = 3;
            _engineId = new OctetString();
            _engineBoots = new Integer32();
            _engineTime = new Integer32();
            _authentication = AuthenticationDigests.None;

            _securityName = new OctetString();
            _authenticationSecret = new MutableByte();
            _authenticationParameters = new OctetString();
            _privacySecret = new MutableByte();
            _privacy = PrivacyProtocols.None;
            _privacyParameters = new OctetString();
        }
 /// <summary>
 /// Copy all relevant values from the SnmpV3Packet class. Do not use this class for
 /// updating the SNMP version 3 discovery process results because secret name, authentication
 /// and privacy values are updated as well which discovery process doesn't use.
 /// </summary>
 /// <param name="packet"><see cref="SnmpV3Packet"/> cast as <see cref="SnmpPacket"/></param>
 /// <exception cref="SnmpInvalidVersionException">Thrown when SNMP packet class other then version 3 
 /// is passed as parameter</exception>
 public void UpdateValues(SnmpPacket packet)
 {
     if (packet is SnmpV3Packet)
     {
         SnmpV3Packet pkt = (SnmpV3Packet)packet;
         _authenticationProtocol = pkt.USM.Authentication;
         _privacyProtocol = pkt.USM.Privacy;
         _authenticationSecret.Set(pkt.USM.AuthenticationSecret);
         _privacySecret.Set(pkt.USM.PrivacySecret);
         _securityName.Set(pkt.USM.SecurityName);
         if (pkt.MaxMessageSize < _maxMessageSize.Value)
             _maxMessageSize.Value = pkt.MaxMessageSize;
         UpdateDiscoveryValues(pkt);
     }
     else
         throw new SnmpInvalidVersionException("Invalid SNMP version.");
 }
        /// <summary>
        /// Reset the class. Initialize all member values to class defaults.
        /// </summary>
        public void Reset()
        {
            _engineId = new OctetString();
            _engineBoots = new Integer32();
            _engineTime = new Integer32();

            _engineTimeStamp = DateTime.MinValue;

            _privacyProtocol = PrivacyProtocols.None;
            _authenticationProtocol = AuthenticationDigests.None;

            _privacySecret = new MutableByte();
            _authenticationSecret = new MutableByte();

            _contextEngineId = new OctetString();
            _contextName = new OctetString();
            _securityName = new OctetString();

            // max message size is initialized to 64KB by default. It will be
            // to the smaller of the two values after discovery process
            _maxMessageSize = new Integer32(64 * 1024);

            _reportable = true;

            _privacyKey = null;
            _authenticationKey = null;
        }
 /// <summary>
 /// Prepare class for noAuthNoPriv operations. Set authentication and privacy protocols to none.
 /// </summary>
 /// <param name="securityName">User security name</param>
 public void noAuthNoPriv(String securityName)
 {
     _securityName.Set(securityName);
     _authenticationProtocol = AuthenticationDigests.None;
     _authenticationSecret.Clear();
     _privacyProtocol = PrivacyProtocols.None;
     _privacySecret.Clear();
 }
 /// <summary>
 /// Prepare class for authPriv operations.
 /// </summary>
 /// <param name="securityName">User security name</param>
 /// <param name="authDigest">Authentication protocol</param>
 /// <param name="authSecret">Authentication secret (password)</param>
 /// <param name="privProtocol">Privacy protocol</param>
 /// <param name="privSecret">Privacy secret (encryption password)</param>
 public void authPriv(String securityName, AuthenticationDigests authDigest, String authSecret, PrivacyProtocols privProtocol, String privSecret)
 {
     _securityName.Set(securityName);
     _authenticationProtocol = authDigest;
     _authenticationSecret.Set(authSecret);
     _privacyProtocol = privProtocol;
     _privacySecret.Set(privSecret);
 }
 /// <summary>
 /// Prepare class for authNoPriv operations. Set privacy protocol to none
 /// </summary>
 /// <param name="securityName">User security name</param>
 /// <param name="authDigest">Authentication protocol</param>
 /// <param name="authSecret">Authentication secret (password)</param>
 public void authNoPriv(String securityName, AuthenticationDigests authDigest, String authSecret)
 {
     _securityName.Set(securityName);
     _authenticationProtocol = authDigest;
     _authenticationSecret.Set(authSecret);
     _privacyProtocol = PrivacyProtocols.None;
     _privacySecret.Clear();
 }
 /// <summary>
 /// Copy constructor. Initialize the class with the values of the parameter class values.
 /// </summary>
 /// <param name="second">Parameter class.</param>
 public SecureAgentParameters(SecureAgentParameters second)
     : this()
 {
     this._contextEngineId.Set(second.ContextEngineId);
     this._contextName.Set(second.ContextName);
     this._engineBoots.Value = second.EngineBoots.Value;
     this._engineId.Set(second.EngineId);
     this._engineTime.Value = second.EngineTime.Value;
     this._engineTimeStamp = second.EngineTimeStamp();
     this._maxMessageSize.Value = second.MaxMessageSize.Value;
     this._privacyProtocol = second.Privacy;
     this._privacySecret.Set(second.PrivacySecret);
     this._authenticationProtocol = second.Authentication;
     this._authenticationSecret.Set(second.AuthenticationSecret);
     this._reportable = second.Reportable;
     this._securityName.Set(second.SecurityName);
     if( second.AuthenticationKey != null )
         this._authenticationKey = (byte[])second.AuthenticationKey.Clone();
     if( second.PrivacyKey != null )
         this._privacyKey = (byte[])second.PrivacyKey.Clone();
 }
Example #17
0
        /// <summary>
        /// Construct and send SNMP v3 authPriv Trap
        /// </summary>
        /// <param name="receiver">Trap receiver IP address</param>
        /// <param name="receiverPort">Trap receiver UDP port number</param>
        /// <param name="engineId">Sender SNMP engineId</param>
        /// <param name="senderEngineBoots">Sender SNMP engine boots</param>
        /// <param name="senderEngineTime">Sender SNMP engine time</param>
        /// <param name="senderUserName">Security (user) name</param>
        /// <param name="senderUpTime">Sender upTime</param>
        /// <param name="trapObjectID">Trap object ID</param>
        /// <param name="varList">Variable binding list</param>
        /// <param name="authDigest">Authentication digest. See <see cref="AuthenticationDigests"/> enumeration for
        /// available digests</param>
        /// <param name="authSecret">Authentication secret</param>
        /// <param name="privProtocol">Privacy protocol. See <see cref="PrivacyProtocols"/> enumeration for
        /// available privacy protocols.</param>
        /// <param name="privSecret">Privacy secret</param>
        public void SendV3Trap(IpAddress receiver, int receiverPort, byte[] engineId, Int32 senderEngineBoots,
			Int32 senderEngineTime, string senderUserName, UInt32 senderUpTime, Oid trapObjectID, VbCollection varList,
			AuthenticationDigests authDigest, byte[] authSecret, PrivacyProtocols privProtocol, byte[] privSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();
            packet.Pdu.Type = PduType.V2Trap;
            packet.authPriv(ASCIIEncoding.UTF8.GetBytes(senderUserName), authSecret, authDigest,privSecret, privProtocol);
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Example #18
0
 /// <summary>
 /// Set packet security to authentication enabled and privacy protection enabled (SNMP v3 mode authPriv)
 /// </summary>
 /// <param name="userName">User name</param>
 /// <param name="authenticationPassword">Authentication password</param>
 /// <param name="authenticationProtocol">Authentication protocol. See definitions in <see cref="AuthenticationDigests"/> enumeration.</param>
 /// <param name="privacyPassword">Privacy protection password.</param>
 /// <param name="privacyProtocol">Privacy protocol. See definitions in <see cref="PrivacyProtocols"/> enumeration.</param>
 public void authPriv(byte[] userName, byte[] authenticationPassword, AuthenticationDigests authenticationProtocol, byte[] privacyPassword, PrivacyProtocols privacyProtocol)
 {
     NoAuthNoPriv(userName); // reset authentication and privacy values and set user name
     _msgFlags.Authentication = true;
     _userSecurityModel.AuthenticationSecret.Set(authenticationPassword);
     _userSecurityModel.Authentication = authenticationProtocol;
     _msgFlags.Privacy = true;
     _userSecurityModel.PrivacySecret.Set(privacyPassword);
     _userSecurityModel.Privacy = privacyProtocol;
 }
Example #19
0
        static void Main(string[] args)
        {
            InitLogger(true);
            AuthenticationDigests authDigest      = AuthenticationDigests.None;
            PrivacyProtocols      privacyprotocol = PrivacyProtocols.None;
            string       ip           = "172.19.27.8";
            int          port         = 161;
            VbCollection vbCollection = null;
            string       community    = "public";
            UdpTarget    target       = null;
            int          version      = 2;
            SnmpV2Packet result2      = null;
            int          ErrorStatus  = -1;
            int          ErrorIndex   = -1;

            string sidbase2 = "1.3.6.1.4.1.1429.2.2.6.5.12.3.1.2.";
            string NameBase = "1.3.6.1.4.1.1429.2.2.6.5.12.3.1.4.";
            string sidbase  = "1.3.6.1.4.1.8813.2.366";

            try
            {
                String     snmpAgent     = "172.19.27.8";
                String     snmpCommunity = "public";
                SimpleSnmp snmp          = new SimpleSnmp(snmpAgent, snmpCommunity);
                // Create a request Pdu
                Pdu pdu = new Pdu();
                pdu.Type = PduType.GetNext;
                List <string> lst1 = new List <string>();
                List <string> lst2 = new List <string>();

                string sid         = "";
                string channelName = "";

                Dictionary <string, string> channelList = new Dictionary <string, string>();
                Dictionary <Oid, AsnType>   result      = null;

                for (int i = 0; i < 1; i++)
                {
                    sid         = "";
                    channelName = "";
                    result      = snmp.GetNext(SnmpVersion.Ver2, new string[] { (sidbase + i) });
                    if (result == null)
                    {
                        logger.Debug("Request failed.");
                    }
                    else
                    {
                        foreach (KeyValuePair <Oid, AsnType> entry in result)
                        {
                            if (entry.Key.ToString().Contains(sidbase))
                            {
                                sid = entry.Value.ToString();
                            }
                            else
                            {
                                i = 100;
                            }
                        }
                    }
                    result = snmp.GetNext(SnmpVersion.Ver2, new string[] { (NameBase + i) });
                    if (result == null)
                    {
                        logger.Debug("Request failed.");
                    }
                    else
                    {
                        foreach (KeyValuePair <Oid, AsnType> entry in result)
                        {
                            if (entry.Key.ToString().Contains(NameBase))
                            {
                                channelName = entry.Value.ToString();
                            }
                        }
                    }

                    if (!sid.Equals("") && !channelName.Equals(""))
                    {
                        channelList.Add(sid, channelName);
                    }
                }

                foreach (var item in channelList)
                {
                    logger.Debug(item.Key + ":" + item.Value);
                }
            }
            catch (Exception e)
            {
                logger.Debug(e.Message);
                logger.Debug(e.StackTrace);
            }

            /*
             * try
             * {
             *  VbCollection coll = new VbCollection();
             *  coll.Add("1.3.6.1.4.1.1429.2.2.6.5.2.1.1.1");
             *  coll.Add("1.3.6.1.4.1.1429.2.2.6.5.2.1.1.2");
             *  Pdu pdu = new Pdu(coll, PduType.GetBulk, 0);
             *  pdu.MaxRepetitions = 10;
             *  String snmpAgent = "172.19.54.30";
             *  String snmpCommunity = "public";
             *  SimpleSnmp snmp = new SimpleSnmp(snmpAgent, snmpCommunity);
             *  for (int i = 0; i < 1; i++)
             *  {
             *      Dictionary<Oid, AsnType> result = snmp.GetBulk(pdu);
             *
             *      if (result == null)
             *      {
             *          logger.Debug("Request failed.");
             *      }
             *      else
             *      {
             *          logger.Debug("result size: " + result.Count);
             *          string filename = "D:\\Amir\\SNMP " + i + ".txt";
             *          using (System.IO.StreamWriter file =
             *          new System.IO.StreamWriter(filename))
             *          {
             *              foreach (KeyValuePair<Oid, AsnType> entry in result)
             *              {
             *                  var x = entry.Value;
             *                  file.WriteLine("{0} = {1}: {2}", entry.Key.ToString(), SnmpConstants.GetTypeName(entry.Value.Type),
             *                  entry.Value.ToString());
             *              }
             *          }
             *
             *      }
             *  }
             *
             *
             * }
             * catch (Exception e)
             * {
             *
             *  logger.Debug(e.Message);
             *  logger.Debug(e.StackTrace);
             * }
             */
            /*try
             * {
             *  IpAddress ipa = new IpAddress(ip);
             *  target = new UdpTarget((IPAddress)ipa);
             *  target.Port = port;
             *  // Construct a Protocol Data Unit (PDU)
             *  Pdu pdu = new Pdu(PduType.Get);
             *  // Set the request type (default is Get)
             *  // pdu.Type = PduType.Get;
             *  // Add variables you wish to query
             *  pdu.VbList.Add(oid); //oid);
             *  OctetString communityOctet = new OctetString(community);
             *  AgentParameters param = new AgentParameters(communityOctet);
             *
             *
             *
             *  param.Version = SnmpVersion.Ver2;
             *  logger.Debug("before get");
             *  result2 = (SnmpV2Packet)target.Request(pdu, param);
             *  logger.Debug("after get");
             *
             *  vbCollection = result2.Pdu.VbList;
             *  ErrorStatus = result2.Pdu.ErrorStatus;
             *  ErrorIndex = result2.Pdu.ErrorIndex;
             *
             *  if (ErrorStatus != 0)
             *  {
             *      // agent reported an error with the request
             *      logger.Debug("Error in SNMP reply. Error {0} index {1}",
             *          ErrorStatus, ErrorIndex);
             *  }
             *  else
             *  {
             *      if (vbCollection != null)
             *      {
             *          foreach (Vb v in vbCollection)
             *          {
             *              logger.Debug("OID={0}\r\nType={1}\r\nValue:{2}",
             *                  v.Oid.ToString(),
             *                  SnmpConstants.GetTypeName(v.Value.Type), v.Value.ToString());
             *          }
             *      }
             *      else logger.Debug("VB COLLECTION IS NULL");
             *  }
             *  target.Close();
             * }
             * catch (Exception ex)
             * {
             *  if (target != null)
             *      target.Close();
             *  logger.Debug("Exception: " + ex.Message + " type: " + ex.GetType().ToString());
             * }
             */
            /*
             * string oid = "";
             * string ip = "";
             * int port = 161;
             * string securityuser = "";
             * string authenticationdigest = "";
             * AuthenticationDigests authDigest = AuthenticationDigests.None;
             * string authenticationpassword = "";
             * PrivacyProtocols privacyprotocol = PrivacyProtocols.None;
             * string privacyprotocolstring = "";
             * string privacyprotocolpassword = "";
             * string community = "";
             * int version = -1;
             * SnmpV3Packet result3;
             * SnmpV1Packet result1;
             * SnmpV2Packet result2;
             *
             * int ErrorStatus = -1;
             * int ErrorIndex = -1;
             * if (args.Length == 0)
             * {
             *  Console.WriteLine("Specify arguments:\r\n" +
             *  "-v:version (Example: -v:1,-v:2c, -v:3)\r\n" +
             *  "-r:IP (Example: -r:192.168.1.0)\r\n" +
             *  "-p:port (Optional, default 161, example: -p:555\r\n" +
             *  "-o:OID (Example: -o:1.3.6.1.2.1.1.2.0" +
             *  "-c:community_string (Example: -c:public)\r\n" +
             *  "-ap:AuthenticationDigest SHA/MD5(Example: -ap:SHA)\r\n" +
             *  "-aw:AuthenticationPassword\r\n" +
             *  "-pp:PrivacyProtocol DES/AES128/AES192/AES256/TripleDES (Example: -pp:AES128)\r\n" +
             *  "-pp:PrivacyPassword\r\n" +
             *  "-sn:SecurityName");
             *  return;
             * }
             * else
             * {
             *  foreach (string arg in args)
             *  {
             *      if (arg.IndexOf("-v:") == 0)
             *      {
             *          if (arg.Substring(3) == "1")
             *              version = 1;
             *          if (arg.Substring(3) == "2c")
             *              version = 2;
             *          if (arg.Substring(3) == "3")
             *              version = 3;
             *      }
             *      if (arg.IndexOf("-o:") == 0)
             *      {
             *          oid = arg.Substring(3);
             *      }
             *      if (arg.IndexOf("-r:") == 0)
             *      {
             *          ip = arg.Substring(3);
             *      }
             *      if (arg.IndexOf("-sn:") == 0)
             *      {
             *          securityuser = arg.Substring(4);
             *      }
             *      if (arg.IndexOf("-c:") == 0)
             *      {
             *          community = arg.Substring(3);
             *      }
             *      if (arg.IndexOf("-p:") == 0)
             *      {
             *          string ports = arg.Substring(3);
             *          try
             *          {
             *              port = Int32.Parse(ports);
             *          }
             *          catch (Exception ex)
             *          {
             *              port = -1;
             *              Console.WriteLine("Not correct port value: " + ports);
             *              break;
             *          }
             *      }
             *      if (arg.IndexOf("-ap:") == 0)
             *      {
             *          authenticationdigest = arg.Substring(4);
             *          if (String.Compare(authenticationdigest, "SHA", true) == 0)
             *              authDigest = AuthenticationDigests.SHA1;
             *          if (String.Compare(authenticationdigest, "MD5", true) == 0)
             *              authDigest = AuthenticationDigests.MD5;
             *      }
             *      if (arg.IndexOf("-aw:") == 0)
             *      {
             *          authenticationpassword = arg.Substring(4);
             *      }
             *      if (arg.IndexOf("-pp:") == 0)
             *      {
             *          privacyprotocolstring = arg.Substring(4);
             *          if (String.Compare(privacyprotocolstring, "DES", true) == 0)
             *              privacyprotocol = PrivacyProtocols.DES;
             *          if (String.Compare(privacyprotocolstring, "AES128", true) == 0)
             *              privacyprotocol = PrivacyProtocols.AES128;
             *          if (String.Compare(privacyprotocolstring, "AES192", true) == 0)
             *              privacyprotocol = PrivacyProtocols.AES192;
             *          if (String.Compare(privacyprotocolstring, "AES256", true) == 0)
             *              privacyprotocol = PrivacyProtocols.AES256;
             *          if (String.Compare(privacyprotocolstring, "TripleDES", true) == 0)
             *              privacyprotocol = PrivacyProtocols.TripleDES;
             *      }
             *      if (arg.IndexOf("-pw:") == 0)
             *      {
             *          privacyprotocolpassword = arg.Substring(4);
             *      }
             *  }
             * }
             * if (port == -1)
             * {
             *  Console.WriteLine("Not valid port: " + port.ToString());
             *  return;
             * }
             * if ((version < 1) || (version > 3))
             * {
             *  Console.WriteLine("Not valid version: ");
             *  return;
             * }
             */
        }
Example #20
0
        /// <summary>
        /// Reset the class. Initialize all member values to class defaults.
        /// </summary>
        public void Reset()
        {
            _address = new IpAddress(System.Net.IPAddress.Loopback);
            _port = 161;
            _version = SnmpVersion.Ver3;
            _timeout = 2000;
            _retry = 1;

            _engineId = new OctetString();
            _engineBoots = new Integer32();
            _engineTime = new Integer32();

            _engineTimeStamp = DateTime.MinValue;

            _privacyProtocol = PrivacyProtocols.None;
            _authenticationProtocol = AuthenticationDigests.None;

            _privacySecret = new MutableByte();
            _authenticationSecret = new MutableByte();

            _contextEngineId = new OctetString();
            _contextName = new OctetString();
            _securityName = new OctetString();

            // max message size is initialized to 64KB by default. It will be
            // to the smaller of the two values after discovery process
            _maxMessageSize = new Integer32(64 * 1024);

            _reportable = true;
        }