1、UdpTransportUdpTransportusing System;using System.Net;using System.Net.Sockets;namespace SnmpSharpNet / 摘要: / IP/UDP transport class. public class UdpTransport : IDisposable / 摘要: / Flag showing if class is using IPv6 or IPv4 protected bool _isIPv6; / / 摘要: / Internal variable used to disable host I
2、P address/port number check on received / SNMP reply packets. If this option is disabled (default) only replies from / the IP address/port number combination to which the request was sent will / be accepted as valid packets. This value is set in the AgentParameters class / and is only valid for SNMP
3、 v1 and v2c requests. protected bool _noSourceCheck; / / 摘要: / Socket protected Socket _socket; / 摘要: / Constructor. Initializes and binds the Socket class / / 参数: / useV6: / Set to true if you wish to initialize the transport for IPv6 public UdpTransport(bool useV6); / 摘要: / Is class busy. This pro
4、perty is true when class is servicing another request, / false if ready to process a new request. public bool IsBusy get; / / 摘要: / Flag used to determine if class is using IP version 6 (true) or IP version / 4 (false) public bool IsIPv6 get; / 摘要: / Close network socket public void Close(); / / 摘要:
5、 / Dispose of the class. public void Dispose(); / / 摘要: / Initialize class socket / / 参数: / useV6: / Should socket be initialized for IPv6 (true) of IPv4 (false) protected void initSocket(bool useV6); / / 摘要: / Make sync request using IP/UDP with request timeouts and retries. / / 参数: / peer: / SNMP
6、agent IP address / / port: / SNMP agent port number / / buffer: / Data to send to the agent / / bufferLength: / Data length in the buffer / / timeout: / Timeout in milliseconds / / retries: / Maximum number of retries. 0 = make a single request with no retry attempts / / 返回结果: / Byte array returned
7、by the agent. Null on error / / 异常: / SnmpSharpNet.SnmpException: / Thrown on request timed out. SnmpException.ErrorCode is set to SnmpException.RequestTimedOut / constant. / / SnmpSharpNet.SnmpException: / Thrown when IPv4 address is passed to the v6 socket or vice versa public byte Request(IPAddre
8、ss peer, int port, byte buffer, int bufferLength, int timeout, int retries); SnmpVersionusing System;namespace SnmpSharpNet / 摘要: / SNMP Version number enumeration public enum SnmpVersion / 摘要: / SNMP version 1 Ver1 = 0, / / 摘要: / SNMP version 2c Ver2 = 1, / / 摘要: / SNMP version 3 Ver3 = 3, Pduusing
9、 System;using System.Collections;using System.Collections.Generic;using System.Reflection;namespace SnmpSharpNet / 摘要: / SNMP Protocol Data Unit / / 备注: / SNMP PDU class that is the bases for all SNMP requests and replies. It is / capable of processing SNMPv1 GET, GET-NEXT, REPLY and SNMPv2 GET, GET
10、-NEXT, / GET-BULK, REPLY, V2TRAP, INFORM and REPORT PDUs. Pdu pdu = new Pdu(); pdu.Type / = PduType.Get; pdu.VbList.AddVb(1.3.6.1.2.1.1.1.0); pdu.VbList.AddVb(1.3.6.1.2.1.1.2.0); / By default, Pdu class initializes the RequestId (unique identifier of each / SNMP request made by the manager) with a r
11、andom value. User can force a new, / random request id generation at the time packet is encoding by changing RequestId / to 0. If you wish to set a specific RequestId, you can do it this way: Pdu / pdu = new Pdu(); pdu.Type = PduType.GetNext; pdu.RequestId = 11; / Set a / custom request id pdu.VbLis
12、t.AddVb(1.3.6.1.2.1.1); Pdu types with special / options are notification PDUs, V2TRAP and INFORM, and Get-Bulk requests. / Get-Bulk request is available in version 2c and 3 of the SNMP. Two special / options can be set for these requests, NonRepeaters and MaxRepetitions. NonRepeaters / is a value t
13、elling the agent how many OIDs in the VbList are to be treated / as a single GetNext request. MaxRepeaters tells the agent how many variable / bindings to return in a single Pdu for each requested Oid. public class Pdu : AsnType, ICloneable, IEnumerable, IEnumerable / 摘要: / Error index value. / / 备注
14、: / Points to the Vb sequence that caused the error. If not Vb the cause of the / error, or if there is no error, this value is 0. protected Integer32 _errorIndex; / / 摘要: / Error status value. / / 备注: / See SnmpSharpNet.SnmpConstants class for definition of error values. If no / error is encountere
15、d, this value is set to 0. protected Integer32 _errorStatus; / / 摘要: / Request id value. / / 备注: / Integer32 value that uniquely represents this request. Used to match requests / and replies. protected Integer32 _requestId; / / 摘要: / SNMPv2 trap second Vb is the trap object ID. / / 备注: / This variab
16、le should be set to the trap OID and will be inserted into the / encoded packet. protected Oid _trapObjectID; / / 摘要: / SNMPv2 trap first Vb is the trap time stamp. To create an SNMPv2 TRAP packet, / set the timestamp value in this variable protected TimeTicks _trapTimeStamp; / / 摘要: / Variable bind
17、ing collection protected VbCollection _vbs; / 摘要: / Constructor. / / 备注: / Initializes all values to NULL and PDU type to GET public Pdu(); / / 摘要: / Constructor / / 参数: / pdu: / Pdu class to use as source of information to initilize this class. / / 备注: / Initialize class from the passed pdu class.
18、public Pdu(Pdu pdu); / / 摘要: / Constructor. / / 参数: / pduType: / Pdu type. For available values see SnmpSharpNet.PduType / / 备注: / Create Pdu of specific type. public Pdu(PduType pduType); / / 摘要: / Constructor. / / 参数: / vbs: / VarBind list to initialize the internal VbList to. / / 备注: / Sets the V
19、arBind list to the Clone copy of the supplied list. public Pdu(VbCollection vbs); / / 摘要: / Constructor. / / 参数: / vbs: / VarBind list / / type: / PDU type / / requestId: / Request id / / 备注: / Initializes PDU class with supplied values. public Pdu(VbCollection vbs, PduType type, int requestId); / 摘
20、要: / ErrorIndex Pdu value / / 异常: / SnmpSharpNet.SnmpInvalidPduTypeException: / Thrown when property is access for GetBulk Pdu / / 备注: / Error index points to the VbList entry that ErrorStatus error code refers / to. Valid for all Pdu types except GetBulk requests. public int ErrorIndex get; set; /
21、/ 摘要: / ErrorStatus Pdu value / / 异常: / SnmpSharpNet.SnmpInvalidPduTypeException: / Thrown when property is access for GetBulk Pdu / / 备注: / Stores error status returned by the SNMP agent. Value 0 represents no error. / Valid for all Pdu types except GetBulk requests. public int ErrorStatus get; set
22、; / / 摘要: / Tells SNMP Agent how many VBs to include in a single request. Only valid / on GETBULK requests. / / 异常: / SnmpSharpNet.SnmpInvalidPduTypeException: / Thrown when PDU type is not GET-BULK public int MaxRepetitions get; set; / / 摘要: / Get/Set GET-BULK NonRepeaters value / / 异常: / SnmpSharp
23、Net.SnmpInvalidPduTypeException: / Thrown when PDU type is not GET-BULK / / 备注: / Non repeaters variable tells the SNMP Agent how many GETNEXT like variables / to retrieve (single Vb returned per request) before MaxRepetitions value / takes affect. If you wish to retrieve as many values as you can i
24、n a single / request, set this value to 0. public int NonRepeaters get; set; / / 摘要: / SNMP packet request id that is sent to the SNMP agent. SET this value before / making SNMP requests. public int RequestId get; set; / / 摘要: / Get TRAP ObjectID class from SNMPv2 TRAP and INFORM PDUs / / 异常: / Snmp
25、SharpNet.SnmpInvalidPduTypeException: / Thrown when property is access for a Pdu of a type other then V2TRAP, INFORM / or RESPONSE public Oid TrapObjectID get; set; / / 摘要: / Get TRAP TimeStamp class from SNMPv2 TRAP and INFORM PDUs public TimeTicks TrapSysUpTime get; / / 摘要: / Get or SET the PDU ty
26、pe. Available types are GET, GETNEXT, SET, GETBULK. / PDU types are defined in Pdu class. public PduType Type get; set; / / 摘要: / Return the number of VB entries in the VarBind list public int VbCount get; / / 摘要: / VarBind list public VbCollection VbList get; / 摘要: / Indexed access to VarBind colle
27、ction of the Pdu. / / 参数: / index: / Index position of the VarBind entry / / 返回结果: / VarBind entry at the specified index / / 异常: / System.IndexOutOfRangeException: / Thrown when index is outside the bounds of the collection public Vb thisint index get; / / 摘要: / Access variable bindings using Vb Oi
28、d value / / 参数: / oid: / Required Oid value / / 返回结果: / Variable binding with the Oid matching the parameter, otherwise null public Vb thisOid oid get; / / 摘要: / Access variable bindings using Vb Oid value in the string format / / 参数: / oid: / Oid value in string representation / / 返回结果: / Variable
29、binding with the Oid matching the parameter, otherwise null public Vb thisstring oid get; / 摘要: / Clone this object / / 返回结果: / Copy of this object cast as type System.Object public override object Clone(); / / 摘要: / Decode BER encoded Pdu / / 参数: / buffer: / BER encoded buffer / / offset: / The offset byte to begin decoding / / 返回结果: / Buffer position after the decoded value / / 异常: / System.OverflowException: / Thrown when header points to mor
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1