Ejemplo n.º 1
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="EPrivacyProtocols"/> enumeration for
        /// available privacy protocols.
        /// </param>
        /// <param name="privSecret">Privacy secret</param>
        public void SendV3Trap(
            IpAddress receiver,
            int receiverPort,
            byte[] engineId,
            int senderEngineBoots,
            int senderEngineTime,
            string senderUserName,
            uint senderUpTime,
            Oid trapObjectID,
            VbCollection varList,
            AuthenticationDigests authDigest,
            byte[] authSecret,
            EPrivacyProtocols privProtocol,
            byte[] privSecret
            )
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = EPduType.V2Trap;
            packet.AuthPriv(Encoding.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.MessageFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set VbList
 /// </summary>
 /// <remarks>
 /// Copy variable bindings from argument <see cref="VbCollection"/> into this classes variable
 /// binding collection
 /// </remarks>
 /// <param name="value"><see cref="VbCollection"/> to copy variable bindings from</param>
 public void SetVbList(VbCollection value)
 {
     _vbs.Clear();
     foreach (Vb v in value)
     {
         _vbs.Add(v);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Create SNMP-GetBulk Pdu
        /// </summary>
        /// <remarks>
        /// Helper static function to create GETBULK PDU from the supplied VarBind list. MaxRepetitions are set to
        /// 256 and nonRepeaters are set to 0.
        /// </remarks>
        /// <param name="vbs">VarBind list</param>
        /// <returns>Newly constructed GETBULK PDU</returns>
        public static Pdu GetBulkPdu(VbCollection vbs)
        {
            Pdu p = new Pdu(vbs);

            p.Type           = PduType.Get;
            p.MaxRepetitions = 256;
            p.NonRepeaters   = 0;
            return(p);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create SNMP-GetNext Pdu
        /// </summary>
        /// <remarks>
        /// Helper static function to create GETNEXT PDU from the supplied VarBind list. Don't forget to set
        /// request id for the PDU.
        /// </remarks>
        /// <param name="vbs">VarBind list</param>
        /// <returns>Newly constructed GETNEXT PDU</returns>
        public static Pdu GetNextPdu(VbCollection vbs)
        {
            Pdu p = new Pdu(vbs);

            p.Type        = PduType.GetNext;
            p.ErrorIndex  = 0;
            p.ErrorStatus = 0;
            return(p);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Add content of the VbCollection to the end of the collection.
 /// </summary>
 /// <param name="varList">Variable Binding collection</param>
 public void Add(VbCollection varList)
 {
     if (varList != null)
     {
         foreach (Vb v in varList)
         {
             Add(v);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Duplicate Vbs object
        /// </summary>
        /// <returns>Duplicate of the Vbs object</returns>
        public override Object Clone()
        {
            VbCollection vb = new VbCollection();

            foreach (Vb v in this)
            {
                vb.Add(v);
            }
            return(vb);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create SNMP-SET Pdu
        /// </summary>
        /// <remarks>
        /// Helper static function to create SET PDU from the supplied VarBind list. Don't forget to set
        /// request id for the PDU.
        /// </remarks>
        /// <param name="vbs">VarBind list</param>
        /// <returns>Newly constructed SET PDU</returns>
        public static Pdu SetPdu(VbCollection vbs)
        {
            var p = new Pdu(vbs)
            {
                Type        = PduType.Set,
                ErrorIndex  = 0,
                ErrorStatus = 0
            };

            return(p);
        }
Ejemplo n.º 8
0
        /// <summary>Constructor</summary>
        public TrapPdu()
        {
            base.Type = (byte)EPduType.Trap;

            enterprise = new Oid();
            agentAddr  = new IpAddress();
            generic    = new Integer32();
            specific   = new Integer32();
            timeStamp  = new TimeTicks();
            variables  = new VbCollection();
        }
Ejemplo n.º 9
0
        /// <summary>Create SNMP-GetBulk Pdu</summary>
        /// <remarks>
        /// Helper static function to create GETBULK PDU from the supplied VarBind list. MaxRepetitions are set to
        /// 256 and nonRepeaters are set to 0.
        /// </remarks>
        /// <param name="vbs">VarBind list</param>
        /// <returns>Newly constructed GETBULK PDU</returns>
        public static Pdu GetBulkPdu(VbCollection vbs)
        {
            Pdu p = new Pdu(vbs)
            {
                Type           = EPduType.GetBulk,
                MaxRepetitions = 100,
                NonRepeaters   = 0,
            };

            return(p);
        }
Ejemplo n.º 10
0
 /// <summary>Constructor.</summary>
 /// <remarks>Initializes all values to NULL and PDU type to GET</remarks>
 public Pdu()
 {
     errorIndex  = new Integer32();
     errorStatus = new Integer32();
     requestId   = new Integer32();
     requestId.SetRandom();
     base.Type     = (byte)EPduType.Get;
     VbList        = new VbCollection();
     TrapSysUpTime = new TimeTicks();
     trapObjectID  = new Oid();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Construct and send SNMP v2 Trap
        /// </summary>
        /// <param name="receiver">Trap receiver IP address</param>
        /// <param name="receiverPort">Trap receiver UDP port number</param>
        /// <param name="community">SNMP community name</param>
        /// <param name="senderUpTime">Sender sysUpTime</param>
        /// <param name="trapObjectID">Trap ObjectID</param>
        /// <param name="varList">Variable binding list</param>
        public void SendV2Trap(IpAddress receiver, int receiverPort, string community, UInt32 senderUpTime,
                               Oid trapObjectID, VbCollection varList)
        {
            SnmpV2Packet packet = new SnmpV2Packet(community);

            packet.Pdu.Type                = PduType.V2Trap;
            packet.Pdu.TrapObjectID        = trapObjectID;
            packet.Pdu.TrapSysUpTime.Value = senderUpTime;
            packet.Pdu.SetVbList(varList);
            SendV2Trap(packet, receiver, receiverPort);
        }
Ejemplo n.º 12
0
        /// <summary>Create SNMP-GetNext Pdu</summary>
        /// <remarks>
        /// Helper static function to create GETNEXT PDU from the supplied VarBind list. Don't forget to set
        /// request id for the PDU.
        /// </remarks>
        /// <param name="vbs">VarBind list</param>
        /// <returns>Newly constructed GETNEXT PDU</returns>
        public static Pdu GetNextPdu(VbCollection vbs)
        {
            Pdu p = new Pdu(vbs)
            {
                Type        = EPduType.GetNext,
                ErrorIndex  = 0,
                ErrorStatus = 0,
            };

            return(p);
        }
Ejemplo n.º 13
0
        /// <summary>Constructor</summary>
        public TrapPdu()
        {
            _asnType    = (byte)PduType.Trap;
            _enterprise = new Oid();
            _agentAddr  = new IpAddress();
            _generic    = new Integer32();
            _specific   = new Integer32();
            _timeStamp  = new TimeTicks();

            VbList = new VbCollection();
        }
Ejemplo n.º 14
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <remarks>
 ///     Initializes all values to NULL and PDU type to GET
 /// </remarks>
 public Pdu()
 {
     _vbs         = null;
     _errorIndex  = new Integer32();
     _errorStatus = new Integer32();
     _requestId   = new Integer32();
     _requestId.SetRandom();
     _asnType       = (byte)PduType.Get;
     _vbs           = new VbCollection();
     _trapTimeStamp = new TimeTicks();
     _trapObjectID  = new Oid();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Construct and send SNMP v1 Trap
        /// </summary>
        /// <param name="receiver">Receiver IP address</param>
        /// <param name="receiverPort">Receiver UDP port number</param>
        /// <param name="community">SNMP community name</param>
        /// <param name="senderSysObjectID">Senders sysObjectID</param>
        /// <param name="senderIpAdress">Sender IP address</param>
        /// <param name="genericTrap">Generic trap code</param>
        /// <param name="specificTrap">Specific trap code</param>
        /// <param name="senderUpTime">Senders sysUpTime</param>
        /// <param name="varList">Variable binding list</param>
        public void SendV1Trap(IpAddress receiver, int receiverPort, string community, Oid senderSysObjectID,
                               IpAddress senderIpAdress, Int32 genericTrap, Int32 specificTrap, UInt32 senderUpTime,
                               VbCollection varList)
        {
            SnmpV1TrapPacket packet = new SnmpV1TrapPacket(community);

            packet.Pdu.Generic  = genericTrap;
            packet.Pdu.Specific = specificTrap;
            packet.Pdu.AgentAddress.Set(senderIpAdress);
            packet.Pdu.TimeStamp = senderUpTime;
            packet.Pdu.VbList.Add(varList);
            packet.Pdu.Enterprise.Set(senderSysObjectID);
            SendV1Trap(packet, receiver, receiverPort);
        }
Ejemplo n.º 16
0
        /// <summary> Constructs a new trap pdu that is identical to the
        /// passed pdu.
        /// </summary>
        /// <param name="second">The object to copy.
        /// </param>
        public TrapPdu(TrapPdu second)
            : this()
        {
            _enterprise.Set(second._enterprise);
            _agentAddr.Set(second._agentAddr);
            _generic.Value   = second.Generic;
            _specific.Value  = second.Specific;
            _timeStamp.Value = second.TimeStamp;

            for (int x = 0; x < second._variables.Count; x++)
            {
                _variables = (VbCollection)second.VbList.Clone();
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initialize the class with values from another <see cref="TrapPdu"/> class.
        /// </summary>
        /// <param name="second">TrapPdu class whose values are used to initialize this class.</param>
        public void Set(TrapPdu second)
        {
            if (second != null)
            {
                _enterprise.Set(second._enterprise);
                _agentAddr.Set(second._agentAddr);
                _generic.Value   = second.Generic;
                _specific.Value  = second.Specific;
                _timeStamp.Value = second.TimeStamp;

                _variables.Clear();

                for (int x = 0; x < second._variables.Count; x++)
                {
                    _variables = (VbCollection)second.VbList.Clone();
                }
            }
            else
            {
                throw new ArgumentException("Invalid argument type.", "value");
            }
        }
Ejemplo n.º 18
0
        /// <summary>Initialize the class with values from another <see cref="TrapPdu"/> class.</summary>
        /// <param name="second">TrapPdu class whose values are used to initialize this class.</param>
        public void Set(TrapPdu second)
        {
            if (second != null)
            {
                enterprise.Set(second.enterprise);
                agentAddr.Set(second.agentAddr);
                generic.Value   = second.Generic;
                specific.Value  = second.Specific;
                timeStamp.Value = second.TimeStamp;

                variables.Clear();

                for (int x = 0; x < second.variables.Count; x++)
                {
                    variables = (VbCollection)second.VbList.Clone();
                }
            }
            else
            {
                throw new ArgumentException("Invalid argument type.", nameof(second));
            }
        }
Ejemplo n.º 19
0
        /// <summary>Construct and send SNMP v3 noAuthNoPriv 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>
        public void SendV3Trap(
            IpAddress receiver,
            int receiverPort,
            byte[] engineId,
            int senderEngineBoots,
            int senderEngineTime,
            string senderUserName,
            uint senderUpTime,
            Oid trapObjectID,
            VbCollection varList
            )
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = EPduType.V2Trap;
            packet.NoAuthNoPriv(Encoding.UTF8.GetBytes(senderUserName));
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MessageFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Ejemplo n.º 20
0
 /// <summary>Constructor.</summary>
 /// <remarks>Sets the VarBind list to the Clone copy of the supplied list.</remarks>
 /// <param name="vbs">VarBind list to initialize the internal VbList to.</param>
 public Pdu(VbCollection vbs)
     : this()
 {
     VbList = (VbCollection)vbs.Clone();
 }
Ejemplo n.º 21
0
 /// <summary>Constructor.</summary>
 /// <remarks>Initializes PDU class with supplied values.</remarks>
 /// <param name="vbs">VarBind list</param>
 /// <param name="type">PDU type</param>
 /// <param name="requestId">Request id</param>
 public Pdu(VbCollection vbs, EPduType type, int requestId)
     : this(vbs)
 {
     this.requestId.Value = requestId;
     base.Type            = (byte)type;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Construct and send SNMP v3 authNoPriv 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 cref="AuthenticationDigests"/> enumeration for
        /// available digests</param>
        /// <param name="authSecret">Authentication 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)
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = PduType.V2Trap;
            packet.authNoPriv(ASCIIEncoding.UTF8.GetBytes(senderUserName), authSecret, authDigest);
            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);
        }
Ejemplo n.º 23
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <remarks>
 ///     Sets the VarBind list to the Clone copy of the supplied list.
 /// </remarks>
 /// <param name="vbs">VarBind list to initialize the internal VbList to.</param>
 public Pdu(VbCollection vbs)
     : this()
 {
     _vbs = (VbCollection)vbs.Clone();
 }
Ejemplo n.º 24
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <remarks>
 ///     Initializes PDU class with supplied values.
 /// </remarks>
 /// <param name="vbs">VarBind list</param>
 /// <param name="type">PDU type</param>
 /// <param name="requestId">Request id</param>
 public Pdu(VbCollection vbs, PduType type, int requestId)
     : this(vbs)
 {
     _requestId.Value = requestId;
     _asnType         = (byte)type;
 }