• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Net.IPAddress类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: EmbeddedSmtpServer

        public EmbeddedSmtpServer(IPAddress address, int port = 25)
        {
            Address = address;
            Port = port;

            Listener = new TcpListener(Address, port);
        }
开发者ID:ahjohannessen,项目名称:EmbeddedMail,代码行数:7,代码来源:EmbeddedSmtpServer.cs


示例17: UdpServer

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="gpsDataParser">数据解析器</param>
        /// <param name="ipAddress">向应用层公开的IP地址</param>
        /// <param name="udpPort">UDP监听端口号</param>
        /// <param name="maxSendPacket">发送数据包的最大长度</param>
        /// <param name="tcpserver"></param>
        /// <param name="bufferSize">收发缓冲区大小</param>
        /// <param name="useTcp">是否使用TCP通信</param>
        public UdpServer(AnalyseBase gpsDataParser,IPAddress ipAddress,int udpPort,int maxSendPacket,int bufferSize,bool useTcp,int udpPortByWeb)
        {
            try
            {
                GpsDataParser = gpsDataParser;

                localIPAddress = ipAddress;
                localPort = udpPort;
                webPort = udpPortByWeb;
                GpsDataParser.AddConnectionEvent += new AnalyseBase.AddConnectionHandler(gpsDataParse_AddConnectionEvent);
                GpsDataParser.DataSource = new IPEndPoint(ipAddress, udpPortByWeb);

                _UdpServerBase = new UdpServerBase(ipAddress, udpPort, maxSendPacket, bufferSize);

                //注册事件
                _UdpServerBase.PostReceivedMsgEvent += new UdpServerBase.PostReceivedMsgHandler(_UdpServerBase_PostReceivedMsgEvent);

                _UdpServerBase.AddSocketToListEvent += new UdpServerBase.AddSocketToListHandler(AdddSocketToList);

                AsyncEventHashtable = new Hashtable();

                CodeKeyHashtable = new Hashtable();
                GatewayRoutingTable = new Dictionary<string, string>();
            }
            catch (Exception ex)
            {
                Logger.Error(ex,null);
            }
        }
开发者ID:hhahh2011,项目名称:CH.Gps,代码行数:39,代码来源:UdpServer.cs


示例18: WksRecord

		/// <summary>
		///   Creates a new instance of the WksRecord class
		/// </summary>
		/// <param name="name"> Name of the host </param>
		/// <param name="timeToLive"> Seconds the record should be cached at most </param>
		/// <param name="address"> IP address of the host </param>
		/// <param name="protocol"> Type of the protocol </param>
		/// <param name="ports"> List of ports which are supported by the host </param>
		public WksRecord(DomainName name, int timeToLive, IPAddress address, ProtocolType protocol, List<ushort> ports)
			: base(name, RecordType.Wks, RecordClass.INet, timeToLive)
		{
			Address = address ?? IPAddress.None;
			Protocol = protocol;
			Ports = ports ?? new List<ushort>();
		}
开发者ID:huoxudong125,项目名称:ARSoft.Tools.Net,代码行数:15,代码来源:WksRecord.cs


示例19: FileServerDLMessage

 public FileServerDLMessage(string targetFile, string saveDir, IPAddress owner, long size)
 {
     this.TargetFile = targetFile;
     this.SaveDir = saveDir;
     this.Owner = owner;
     this.Size = size;
 }
开发者ID:dferens,项目名称:P2PChat,代码行数:7,代码来源:FileServerMessages.cs


示例20: Connect

 public void Connect(IPAddress ip, int port)
 {
     var client = new TcpClientSocket();
     client.OnConnect += onConnected;
     client.Connect(ip, port);
     socket = client;
 }
开发者ID:sschmid,项目名称:NLog,代码行数:7,代码来源:SocketAppenderBase.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.IPEndPoint类代码示例发布时间:2022-05-26
下一篇:
C# Net.HttpWebResponse类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap