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


C# Net.IPAddress类代码示例

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


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

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            var ControllerIPAddress = new IPAddress(new byte[] { 192, 168, 0, 2 });
            var ControllerPort = 40001;
            var ControllerEndPoint = new IPEndPoint(ControllerIPAddress, ControllerPort);
            _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            var header = "@";
            var command = "00C";
            var checksum = "E3";
            var end = "\r\n";
            var data = header + command + checksum + end;
            byte[] bytes = new byte[1024];

            //Start Connect
            _connectDone.Reset();
            watch.Start();
            _client.BeginConnect(ControllerIPAddress, ControllerPort, new AsyncCallback(ConnectCallback), _client);
            //wait 2s
            _connectDone.WaitOne(2000, false);

            var text = (_client.Connected) ? "ok" : "ng";
            richTextBox1.AppendText(text + "\r\n");
            watch.Stop();
            richTextBox1.AppendText("Consumer time: " + watch.ElapsedMilliseconds + "\r\n");
        }
开发者ID:Joncash,项目名称:HanboAOMClassLibrary,代码行数:27,代码来源:AsyncConnectionForm.cs

示例2: IPv4Destination

 public IPv4Destination(IPAddress ip, uint port, bool isOpenExternally)
     : base(ip, port, isOpenExternally)
 {
     if (ip.AddressFamily != AddressFamily.InterNetwork) {
         throw new ArgumentException(String.Format("ip must be IPv4 (was {0})", ip));
     }
 }
开发者ID:codebutler,项目名称:meshwork,代码行数:7,代码来源:IPDestination.cs

示例3: HandleRData

        private void HandleRData(NetBinaryReader nbr)
        {
            long startPos = nbr.BaseStream.Position;

            switch (Type)
            {
                case (QType.A):
                case (QType.AAAA):
                    recordValue = new IPAddress(nbr.ReadBytes(ByteCount));
                    break;
                    /*
                case (QType.NS):
                case (QType.CNAME):
                    recordValue = nbr.ReadLblOrPntString();
                    ReadPadOctets(nbr, startPos);
                    break;
                case (QType.SOA):
                    recordValue = new SOA(nbr);
                    ReadPadOctets(nbr, startPos);
                    break;
                    */
                default:
                    recordValue = nbr.ReadBytes(ByteCount);
                    break;
            }
        }
开发者ID:Arzana,项目名称:Sniffles,代码行数:26,代码来源:DnsAnswer.cs

示例4: IPNetwork

		public IPNetwork(IPAddress address, int cidr)
		{
			if (address == null)
			{
				throw new ArgumentNullException("address");
			}

			int addressBitLength;

			if (address.AddressFamily == AddressFamily.InterNetwork)
			{
				addressBitLength = 32;
			}
			else if (address.AddressFamily == AddressFamily.InterNetworkV6)
			{
				addressBitLength = 128;
			}
			else
			{
				throw new FormatException("Unsupported network address family.");
			}

			if (cidr < 0 || cidr > addressBitLength)
			{
				throw new ArgumentOutOfRangeException("cidr");
			}

			_NetworkAddress = address;
			_CIDR = cidr;
			_Mask = GenerateMask(cidr, addressBitLength);
		}
开发者ID:Philo,项目名称:Revalee,代码行数:31,代码来源:IPNetwork.cs

示例5: StartWebDAV

        /// <summary>
        /// Start the WebDAV interface using the given ip address, port and HTTPSecurity parameters.
        /// </summary>
        /// <param name="myIPAddress">The IPAddress for binding the interface at</param>
        /// <param name="myPort">The port for binding the interface at</param>
        /// <param name="myHttpWebSecurity">A HTTPSecurity class for checking security parameters like user credentials</param>
        public static Exceptional<HTTPServer<GraphDSWebDAV_Service>> StartWebDAV(this AGraphDSSharp myAGraphDSSharp, IPAddress myIPAddress, UInt16 myPort, HTTPSecurity myHttpWebSecurity = null)
        {
            try
            {
                // Initialize WebDAV service
                var _HttpWebServer = new HTTPServer<GraphDSWebDAV_Service>(
                    myIPAddress,
                    myPort,
                    new GraphDSWebDAV_Service(myAGraphDSSharp),
                    myAutoStart: true)
                {
                    HTTPSecurity = myHttpWebSecurity,
                };

                // Register the WebDAV service within the list of services
                // to stop before shutting down the GraphDSSharp instance
                myAGraphDSSharp.ShutdownEvent += new GraphDSSharp.ShutdownEventHandler((o, e) =>
                {
                    _HttpWebServer.StopAndWait();
                });

                return new Exceptional<HTTPServer<GraphDSWebDAV_Service>>(_HttpWebServer);

            }
            catch (Exception e)
            {
                return new Exceptional<HTTPServer<GraphDSWebDAV_Service>>(new GeneralError(e.Message, new System.Diagnostics.StackTrace(e)));
            }
        }
开发者ID:Vadi,项目名称:sones,代码行数:35,代码来源:GraphDSExtensionsWebDAV.cs

示例6: Start

 public void Start(string address, int port, string path)
 {
     IPAddress ipaddr = new IPAddress(address.Split('.').Select(a => (byte)a.to_i()).ToArray());
     WebSocketServer wss = new WebSocketServer(ipaddr, port, this);
     wss.AddWebSocketService<ServerReceiver>(path);
     wss.Start();
 }
开发者ID:cliftonm,项目名称:clifton,代码行数:7,代码来源:WebSocketServerService.cs

示例7: IsLocalIP

        /// <summary>
        /// Checks if a ipv4 address is a local network address / zeroconf
        /// </summary>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static bool IsLocalIP(IPAddress ip)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                byte[] ipBytes = ip.GetAddressBytes();

                //    10.0.0.0 bis  10.255.255.255 :: 10.0.0.0/8       (1 Class C)
                if (ipBytes[0] == 10)
                {
                    return true;
                }

                //  172.16.0.0 bis  172.31.255.255 :: 172.16.0.0/12   (16 Class B)
                if ((ipBytes[0] == 172) && (ipBytes[1] > 15) && (ipBytes[1] < 32))
                {
                    return true;
                }

                // 192.168.0.0 bis 192.168.255.255 :: 192.168/16     (256 Class C)
                if ((ipBytes[0] == 192) && (ipBytes[1] == 168))
                {
                    return true;
                }

                // 169.254.0.0 bis 169.254.255.255 :: 169.254.0.0/16    (Zeroconf)
                if ((ipBytes[0] == 169) && (ipBytes[1] == 255))
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:Avatarchik,项目名称:huffelpuff-irc-bot,代码行数:37,代码来源:Tool.cs

示例8: TryParse

		public static bool TryParse(string ip, out IPAddress address) {
			// Only handle IPv4
			if (ip == null) {
				throw new ArgumentNullException("ip");
			}
			if (ip.Length == 0 || ip == " ") {
				address = new IPAddress(0);
				return true;
			}
			string[] parts = ip.Split('.');
			if (parts.Length != 4) {
				address = null;
				return false;
			}
			uint a = 0;
			for (int i = 0; i < 4; i++) {
				int val;
				if (!int.TryParse(parts[i], out val)) {
					address = null;
					return false;
				}
				a |= ((uint)val) << (i << 3);
			}
			address = new IPAddress((long)a);
			return true;
		}
开发者ID:bradparks,项目名称:DotNetAnywhere,代码行数:26,代码来源:IPAddress.cs

示例9: Blacklist

 public virtual void Blacklist(IPAddress senderAddress)
 {
     if (!_blacklist.ContainsKey(senderAddress))
     {
         _blacklist.Add(senderAddress, true);
     }
 }
开发者ID:newchild,项目名称:MiNET,代码行数:7,代码来源:GreyListManager.cs

示例10: ClientSocket

 public ClientSocket(IPAddress address, int port)
     : base(10, LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType))
 {
     this.Setup(new IPEndPoint(address, port), new ClientMessageProcessor());
     Handler = new Handler();
     Rpc = new BinarySenderStub(this);
 }
开发者ID:karlnp,项目名称:OCTGN,代码行数:7,代码来源:ClientSocket.cs

示例11: SslServer

        public SslServer(X509Certificate2 cert, bool certRequired, SslProtocols enabledProt, bool expectedExcep)
        {
            certificate = cert;
            clientCertificateRequired = certRequired;
            enabledSslProtocols = enabledProt;
            expectedException = expectedExcep;

            if (!certificate.HasPrivateKey)
            {
                Console.WriteLine("ERROR: The cerfiticate does not have a private key.");
                throw new Exception("No Private Key in the certificate file");
            }

            //Get the IPV4 address on this machine which is all that the MF devices support.
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == AddressFamily.InterNetwork)
                {
                    ipAddress = address;
                    break;
                }
            }

            if (ipAddress == null)
                throw new Exception("No IPV4 address found.");

            //Console.WriteLine("ipAddress is: " + ipAddress.ToString());
            //Console.WriteLine("port          is: " + port.ToString());
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:29,代码来源:SslServer.cs

示例12: OpenSocket

 partial void OpenSocket(IPAddress connectedHost, uint connectedPort)
 {
     var ep = new IPEndPoint(connectedHost, (int)connectedPort);
     this._socket = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     this._socket.Connect(ep);
     this._socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
 }
开发者ID:ElanHasson,项目名称:SSIS-Extensions,代码行数:7,代码来源:ChannelForwardedTcpip.NET40.cs

示例13: init

 public void init()
 {
     try
     {
         Console.WriteLine("Init");
         //set up socket
         Socket client = new Socket(AddressFamily.InterNetwork,
         SocketType.Stream, ProtocolType.Tcp);
         //IPHostEntry hostInfo = Dns.Resolve("localhost:8000");
         //IPAddress address = hostInfo.AddressList[0];
         //IPAddress ipAddress = Dns.GetHostEntry("localhost:8000").AddressList[0];
         IPAddress ipAddress = new IPAddress(new byte[] { 128, 61, 105, 215 });
         IPEndPoint ep = new IPEndPoint(ipAddress, 8085);
         client.BeginConnect(ep, new AsyncCallback(ConnectCallback), client);
         connectDone.WaitOne();
         //receiveForever(client);
         byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");
         StateObject state = new StateObject();
         state.workSocket = client;
         client.BeginReceive(buffer, 0, StateObject.BufferSize, 0,
                 new AsyncCallback(ReceiveCallback), state);
         client.Send(msg);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
开发者ID:Ramvling,项目名称:CS4903-Kinect-Improv,代码行数:28,代码来源:NetworkManager.cs

示例14: Handle

        public virtual BEncodedDictionary Handle(string queryString, IPAddress remoteAddress, bool isScrape)
        {
            if (queryString == null)
                throw new ArgumentNullException("queryString");

            return Handle(ParseQuery(queryString), remoteAddress, isScrape);
        }
开发者ID:mrscylla,项目名称:octotorrent,代码行数:7,代码来源:ListenerBase.cs

示例15: RnetTcpConnection

 /// <summary>
 /// Initializes a new connection to RNET.
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="port"></param>
 public RnetTcpConnection(IPAddress ip, int port)
     : this(new IPEndPoint(ip, port))
 {
     Contract.Requires(ip != null);
     Contract.Requires(port >= 0);
     Contract.Requires(port <= 65535);
 }
开发者ID:wasabii,项目名称:rnet,代码行数:12,代码来源:RnetTcpConnection.cs


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