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


C# IPAddress.Equals方法代码示例

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


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

示例1: SendPingAsync

        public Task<PingReply> SendPingAsync(IPAddress address, int timeout, byte[] buffer, PingOptions options)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (buffer.Length > MaxBufferSize)
            {
                throw new ArgumentException(SR.net_invalidPingBufferSize, nameof(buffer));
            }

            if (timeout < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeout));
            }

            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            // Check if address family is installed.
            TestIsIpSupported(address);

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.net_invalid_ip_addr, nameof(address));
            }

            // Need to snapshot the address here, so we're sure that it's not changed between now
            // and the operation, and to be sure that IPAddress.ToString() is called and not some override.
            IPAddress addressSnapshot = (address.AddressFamily == AddressFamily.InterNetwork) ?
                new IPAddress(address.GetAddressBytes()) :
                new IPAddress(address.GetAddressBytes(), address.ScopeId);

            CheckStart();
            try
            {
                return SendPingAsyncCore(addressSnapshot, buffer, timeout, options);
            }
            catch (Exception e)
            {
                Finish();
                return Task.FromException<PingReply>(new PingException(SR.net_ping, e));
            }
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:47,代码来源:Ping.cs

示例2: ParseRouteInfo

		IPAddressCollection ParseRouteInfo (string iface)
		{
			var col = new IPAddressCollection ();
			try {
				using (StreamReader reader = new StreamReader ("/proc/net/route")) {
					string line;
					reader.ReadLine (); // Ignore first line
					while ((line = reader.ReadLine ()) != null) {
						line = line.Trim ();
						if (line.Length == 0)
							continue;

						string [] parts = line.Split ('\t');
						if (parts.Length < 3)
							continue;
						string gw_address = parts [2].Trim ();
						byte [] ipbytes = new byte [4];
						if (gw_address.Length == 8 && iface.Equals (parts [0], StringComparison.OrdinalIgnoreCase)) {
							for (int i = 0; i < 4; i++) {
								if (!Byte.TryParse (gw_address.Substring (i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
									continue;
							}
							IPAddress ip = new IPAddress (ipbytes);
							if (!ip.Equals (IPAddress.Any) && !col.Contains (ip))
								col.InternalAdd (ip);
						}
					}
				}
			} catch {
			}

			return col;
		}
开发者ID:yangjunhua,项目名称:mono,代码行数:33,代码来源:IPInterfaceProperties.cs

示例3: IsBroadcast

 private bool IsBroadcast(IPAddress address)
 {
     if (address.AddressFamily == AddressFamily.InterNetworkV6)
     {
         // No such thing as a broadcast address for IPv6.
         return false;
     }
     else
     {
         return address.Equals(IPAddress.Broadcast);
     }
 }
开发者ID:nbilling,项目名称:corefx,代码行数:12,代码来源:UDPClient.cs

示例4: Equals_Compare_Success

        public static void Equals_Compare_Success()
        {
            IPAddress ip1 = IPAddress.Parse("192.168.0.9"); //IpV4
            IPAddress ip2 = IPAddress.Parse("192.168.0.9"); //IpV4
            IPAddress ip3 = IPAddress.Parse("169.192.1.10"); //IpV4

            IPAddress ip4 = new IPAddress(ipV6AddressBytes1); //IpV6
            IPAddress ip5 = new IPAddress(ipV6AddressBytes1); //IpV6
            IPAddress ip6 = new IPAddress(ipV6AddressBytes2); //IpV6

            Assert.True(ip1.Equals(ip2));
            Assert.True(ip2.Equals(ip1));

            Assert.True(ip1.GetHashCode().Equals(ip2.GetHashCode()));
            Assert.False(ip1.GetHashCode().Equals(ip3.GetHashCode()));

            Assert.False(ip1.Equals(ip3));

            Assert.False(ip1.Equals(ip4)); //IpV4 /= IpV6
            Assert.False(ip1.Equals(null));
            Assert.False(ip1.Equals(""));

            Assert.True(ip4.Equals(ip5));
            Assert.False(ip4.Equals(ip6));

            Assert.True(ip4.GetHashCode().Equals(ip5.GetHashCode()));
            Assert.False(ip4.GetHashCode().Equals(ip6.GetHashCode()));
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:28,代码来源:IPAddressTest.cs

示例5: SendAsync

        private void SendAsync(IPAddress address, int timeout, byte[] buffer, PingOptions options, object userToken)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (buffer.Length > MaxBufferSize)
            {
                throw new ArgumentException(SR.net_invalidPingBufferSize, "buffer");
            }

            if (timeout < 0)
            {
                throw new ArgumentOutOfRangeException("timeout");
            }

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

            // Check if address family is installed.
            TestIsIpSupported(address);

            if (address.Equals(IPAddress.Any) || address.Equals(IPAddress.IPv6Any))
            {
                throw new ArgumentException(SR.net_invalid_ip_addr, "address");
            }

            // FxCop: need to snapshot the address here, so we're sure that it's not changed between the permission
            // check and the operation, and to be sure that IPAddress.ToString() is called and not some override.
            IPAddress addressSnapshot;
            if (address.AddressFamily == AddressFamily.InterNetwork)
            {
                addressSnapshot = new IPAddress(address.GetAddressBytes());
            }
            else
            {
                addressSnapshot = new IPAddress(address.GetAddressBytes(), address.ScopeId);
            }

            CheckStart(true);
            try
            {
                _cancelled = false;
                _asyncOp = AsyncOperationManager.CreateOperation(userToken);
                InternalSend(addressSnapshot, buffer, timeout, options, true);
            }
            catch (Exception e)
            {
                Finish(true);
                throw new PingException(SR.net_ping, e);
            }
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:55,代码来源:ping.cs


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