当前位置: 首页>>代码示例>>C#>>正文


C# OctetString类代码示例

本文整理汇总了C#中OctetString的典型用法代码示例。如果您正苦于以下问题:C# OctetString类的具体用法?C# OctetString怎么用?C# OctetString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OctetString类属于命名空间,在下文中一共展示了OctetString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: sprawdzPolaczenie

        public bool sprawdzPolaczenie(string host1, string commun)
        {
            /*! 
	    	 *Sprawdza, czy pod wpisanymi danymi istnieje jakiś serwer do obsługi.
             */
            string OID = "1.3.6.1.2.1.6.11.0";
            OctetString communityOS = new OctetString(commun);
            AgentParameters param = new AgentParameters(communityOS);
            param.Version = SnmpVersion.Ver1;
            IpAddress agent = new IpAddress(host1);
            UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);

            Pdu pdu = new Pdu(PduType.Get);
            pdu.VbList.Add(OID);
            try
            {
                SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
            }
            catch
            {
                return false;
            }
            host = host1;
            community = commun;
            return true;
        }
开发者ID:Kuczmil,项目名称:RE-SE,代码行数:26,代码来源:dane_geber.cs

示例2: Get

        /// <summary>
        /// Gets a list of variable binds.
        /// </summary>
        /// <param name="version">Protocol version.</param>
        /// <param name="endpoint">Endpoint.</param>
        /// <param name="community">Community name.</param>
        /// <param name="variables">Variable binds.</param>
        /// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
        /// <returns></returns>
        public static IList<Variable> Get(VersionCode version, IPEndPoint endpoint, OctetString community, IList<Variable> variables, int timeout)
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException("endpoint");
            }

            if (community == null)
            {
                throw new ArgumentNullException("community");
            }

            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }

            if (version == VersionCode.V3)
            {
                throw new NotSupportedException("SNMP v3 is not supported");
            }

            var message = new GetRequestMessage(RequestCounter.NextId, version, community, variables);
            var response = message.GetResponse(timeout, endpoint);
            var pdu = response.Pdu();
            if (pdu.ErrorStatus.ToInt32() != 0)
            {
                throw ErrorException.Create(
                    "error in response",
                    endpoint.Address,
                    response);
            }

            return pdu.Variables;
        }
开发者ID:yonglehou,项目名称:sharpsnmplib,代码行数:44,代码来源:Messenger.cs

示例3: Header

        /// <summary>
        /// Initializes a new instance of the <see cref="Header"/> class.
        /// </summary>
        /// <param name="messageId">The message id.</param>
        /// <param name="maxMessageSize">Size of the max message.</param>
        /// <param name="securityBits">The flags.</param>
        /// <param name="securityModel">The security model.</param>
        /// <remarks>If you want an empty header, please use <see cref="Empty"/>.</remarks>
        public Header(Integer32 messageId, Integer32 maxMessageSize, OctetString securityBits, Integer32 securityModel)
        {
            if (messageId == null)
            {
                throw new ArgumentNullException("messageId");
            }

            if (maxMessageSize == null)
            {
                throw new ArgumentNullException("maxMessageSize");
            }

            if (securityBits == null)
            {
                throw new ArgumentNullException("securityBits");
            }

            if (securityModel == null)
            {
                throw new ArgumentNullException("securityModel");
            }

            _messageId = messageId;
            _maxSize = maxMessageSize;
            _flags = securityBits;
            _securityModel = securityModel;
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:35,代码来源:Header.cs

示例4: get

        public string get(string ip, string oid)
        {
            Pdu pdu = new Pdu(PduType.Get);
            pdu.VbList.Add(oid);
            OctetString community = new OctetString("public");
            AgentParameters param = new AgentParameters(community);
            param.Version = SnmpVersion.Ver1;
            {
                IpAddress agent = new IpAddress(ip);
                UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);
                SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);
                if (result != null)
                {
                    if (result.Pdu.ErrorStatus != 0)
                    {

                        return string.Format("Error in SNMP reply. Error {0} index {1} \r\n",
                            result.Pdu.ErrorStatus,
                            result.Pdu.ErrorIndex);
                    }
                    else
                    {
                        return result.Pdu.VbList[0].Value.ToString();
                    }
                }

                else
                {
                    return string.Format("No response received from SNMP agent. \r\n");
                }
                target.Dispose();
            }
        }
开发者ID:hw901013,项目名称:hw901013,代码行数:33,代码来源:EASYSNMP.cs

示例5: SetRequestMessage

        /// <summary>
        /// Creates a <see cref="SetRequestMessage"/> with all contents.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="version">Protocol version</param>
        /// <param name="community">Community name</param>
        /// <param name="variables">Variables</param>
        public SetRequestMessage(int requestId, VersionCode version, OctetString community, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }
            
            if (community == null)
            {
                throw new ArgumentNullException("community");
            }
            
            if (version == VersionCode.V3)
            {
                throw new ArgumentException("only v1 and v2c are supported", "version");
            }
            
            Version = version;
            Header = Header.Empty;
            Parameters = new SecurityParameters(null, null, null, community, null, null);
            SetRequestPdu pdu = new SetRequestPdu(
                requestId,
                ErrorCode.NoError,
                0,
                variables);
            Scope = new Scope(pdu);
            Privacy = DefaultPrivacyProvider.DefaultPair;
 
            _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes();
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:37,代码来源:SetRequestMessage.cs

示例6: GetResponseMessage

        public GetResponseMessage(int requestId, VersionCode version, OctetString community, ErrorCode error, int index, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }
            
            if (community == null)
            {
                throw new ArgumentNullException("community");
            }
            
            if (version == VersionCode.V3)
            {
                throw new ArgumentException("Please use overload constructor for v3", "version");
            }

            Version = version;
            Header = Header.Empty;
            Parameters = new SecurityParameters(null, null, null, community, null, null);
            GetResponsePdu pdu = new GetResponsePdu(
                requestId,
                error,
                index,
                variables);
            Scope = new Scope(pdu);
            Privacy = DefaultPrivacyProvider.DefaultPair;

            _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes();
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:30,代码来源:GetResponseMessage.cs

示例7: OidUnit

 public OidUnit(string path, OctetString data)
     : base(path)
 {
     _path = path;
     _data = data;
     _index = SNMPHelper.GetObjectIndex(new ObjectIdentifier(path));
 }
开发者ID:batas2,项目名称:SNMPMonitor,代码行数:7,代码来源:OidUnit.cs

示例8: SetRequestMessage

        /// <summary>
        /// Creates a <see cref="SetRequestMessage"/> with all contents.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="version">Protocol version</param>
        /// <param name="community">Community name</param>
        /// <param name="variables">Variables</param>
        public SetRequestMessage(int requestId, VersionCode version, OctetString community, IList<Variable> variables)
        {
            if (variables == null)
            {
                throw new ArgumentNullException("variables");
            }
            
            if (community == null)
            {
                throw new ArgumentNullException("community");
            }
            
            if (version == VersionCode.V3)
            {
                throw new ArgumentException("only v1 and v2c are supported", "version");
            }
            
            Version = version;
            Header = Header.Empty;
            Parameters = SecurityParameters.Create(community);
            var pdu = new SetRequestPdu(
                requestId,
                variables);
            Scope = new Scope(pdu);
            Privacy = DefaultPrivacyProvider.DefaultPair;
 
            _bytes = this.PackMessage(null).ToBytes();
        }
开发者ID:lovmoen,项目名称:sharpsnmplib,代码行数:35,代码来源:SetRequestMessage.cs

示例9: TestPhysical

        public void TestPhysical()
        {
            var mac = new OctetString(new byte[] {80, 90, 64, 87, 11, 99});
            Assert.AreEqual("505A40570B63", mac.ToPhysicalAddress().ToString());

            var invalid = new OctetString(new byte[] {89});
            Assert.Throws<InvalidCastException>(() => invalid.ToPhysicalAddress());
        }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:8,代码来源:OctetStringTestFixture.cs

示例10: MD5AuthenticationProvider

 /// <summary>
 /// Initializes a new instance of the <see cref="MD5AuthenticationProvider"/> class.
 /// </summary>
 /// <param name="phrase">The phrase.</param>
 public MD5AuthenticationProvider(OctetString phrase)
 {
     if (phrase == null)
     {
         throw new ArgumentNullException("phrase");
     }
     
     _password = phrase.GetRaw();
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:13,代码来源:MD5AuthenticationProvider.cs

示例11: EthernetAddress

 /// <summary>Constructor. Initialize the class with the value from the <see cref="OctetString"/> argument.
 /// </summary>
 /// <param name="second">Class whose value is used to initialize this class.
 /// </param>
 public EthernetAddress(OctetString second)
     : this()
 {
     if (second.Length < 6)
         throw new System.ArgumentException("Buffer underflow error converting IP address");
     else if (Length > 6)
         throw new System.ArgumentException("Buffer overflow error converting IP address");
     base.Set(second);
 }
开发者ID:griffina,项目名称:SnmpSharpNet,代码行数:13,代码来源:EthernetAddress.cs

示例12: MalformedMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="MalformedMessage"/> class.
        /// </summary>
        /// <param name="messageId">The message id.</param>
        /// <param name="user">The user.</param>
        public MalformedMessage(int messageId, OctetString user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            MessageId = messageId;
            Parameters = new SecurityParameters(null, null, null, user, null, null);
            Pdu = MalformedPdu.Instance;
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:16,代码来源:MalformedMessage.cs

示例13: TestEqual

        public void TestEqual()
        {
            var left = new OctetString("public");
            var right = new OctetString("public");
            Assert.AreEqual(left, right);
            Assert.IsTrue(left != OctetString.Empty);
// ReSharper disable EqualExpressionComparison
            Assert.IsTrue(left == left);
// ReSharper restore EqualExpressionComparison

        }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:11,代码来源:OctetStringTestFixture.cs

示例14: MalformedMessage

        /// <summary>
        /// Initializes a new instance of the <see cref="MalformedMessage"/> class.
        /// </summary>
        /// <param name="messageId">The message id.</param>
        /// <param name="user">The user.</param>
        public MalformedMessage(int messageId, OctetString user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            Header = new Header(messageId);
            Parameters = SecurityParameters.Create(user);
            Scope = DefaultScope;
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:16,代码来源:MalformedMessage.cs

示例15: Get

        /// <summary>
        /// Performs an SNMP get request
        /// </summary>
        /// <param name="log_options">Log options</param>
        /// <param name="ip">IP of target device</param>
        /// <param name="in_community">Community name</param>
        /// <param name="oid">OID</param>
        /// <returns></returns>
        public static SnmpV1Packet Get(LOG_OPTIONS log_options, IPAddress ip, string in_community, string oid, bool get_next)
        {
            // SNMP community name
            OctetString community = new OctetString(in_community);

            // Define agent parameters class
            AgentParameters param = new AgentParameters(community);
            // Set SNMP version to 1 (or 2)
            param.Version = SnmpVersion.Ver1;

            // Construct target
            UdpTarget target = new UdpTarget(ip, 161, 2000, 1);

            // Pdu class used for all requests
            Pdu pdu;
            if (get_next)
            {
                pdu = new Pdu(PduType.GetNext);
            }
            else
            {
                pdu = new Pdu(PduType.Get);
            }
            pdu.VbList.Add(oid); //sysDescr

            // Make SNMP request
            SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);

            // If result is null then agent didn't reply or we couldn't parse the reply.
            if (result != null)
            {
                // ErrorStatus other then 0 is an error returned by
                // the Agent - see SnmpConstants for error definitions
                if (result.Pdu.ErrorStatus != 0)
                {
                    // agent reported an error with the request
                    Logger.Write(log_options, module, "Error in SNMP reply. Error " + result.Pdu.ErrorStatus.ToString() + " index " + result.Pdu.ErrorIndex.ToString());
                }
                else
                {
                    // Reply variables are returned in the same order as they were added
                    //  to the VbList
                    Logger.Write(log_options, module, "OID: " + result.Pdu.VbList[0].Oid.ToString() + " Value: " + SnmpConstants.GetTypeName(result.Pdu.VbList[0].Value.Type) + " : " + result.Pdu.VbList[0].Value.ToString());
                }
            }
            else
            {
                Logger.Write(log_options, module, "No response received from SNMP agent.");
            }
            target.Close();

            return result;
        }
开发者ID:jonathan84clark,项目名称:JTool,代码行数:61,代码来源:SNMP_Tools.cs


注:本文中的OctetString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。