當前位置: 首頁>>代碼示例>>C#>>正文


C# IPAddress.GetNetworkAddress方法代碼示例

本文整理匯總了C#中System.Net.IPAddress.GetNetworkAddress方法的典型用法代碼示例。如果您正苦於以下問題:C# IPAddress.GetNetworkAddress方法的具體用法?C# IPAddress.GetNetworkAddress怎麽用?C# IPAddress.GetNetworkAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Net.IPAddress的用法示例。


在下文中一共展示了IPAddress.GetNetworkAddress方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsInSameSubnet

        public static bool IsInSameSubnet(this IPAddress address2, IPAddress address, IPAddress subnetMask)
        {
            IPAddress network1 = address.GetNetworkAddress(subnetMask);
            IPAddress network2 = address2.GetNetworkAddress(subnetMask);

            return network1.Equals(network2);
        }
開發者ID:kenan99,項目名稱:managedfusion,代碼行數:7,代碼來源:IPAddress.cs

示例2: IsInSameSubnet

        public static bool IsInSameSubnet(this IPAddress address, IPAddress check, byte[] subnetMask)
        {
            if (address.AddressFamily != check.AddressFamily)
                return false;

            IPAddress network1 = address.GetNetworkAddress(subnetMask);
            IPAddress network2 = check.GetNetworkAddress(subnetMask);
            return network1.IsEqual(network2);
        }
開發者ID:jpykie,項目名稱:MPExtended,代碼行數:9,代碼來源:IPAddressExtensions.cs

示例3: SameSubnetAs

        /// <summary>
        /// Compares if 2 IPv6 addresses are within the same Subnet using the Subnet Mask
        /// </summary>
        /// <param name="address1">The first IPv4 address to compare the network IDs for.</param>
        /// <param name="address2">The second IPv4 address to compare the network IDs for.</param>
        /// <param name="subnetBits">The number of MSBs to use for comparing the subnet.</param>
        /// <returns>True if they are part of the same subnet</returns>
        public static bool SameSubnetAs(this IPAddress address1, IPAddress address2, byte subnetBits = 64)
        {
            if (address1.AddressFamily != AddressFamily.InterNetworkV6)
                throw new ArgumentException("must be an IPv6 (InterNetworkV6) address family.", "address1");

            if (address2.AddressFamily != AddressFamily.InterNetworkV6)
                throw new ArgumentException("must be an IPv6 (InterNetworV6) address family.", "address2");

            if (subnetBits > 128)
                throw new ArgumentException("must be between 0 and 128", "subnetBits");

            if (subnetBits != 0)
            {
                IPAddress lIPNet1 = address1.GetNetworkAddress(IPAddressFromBitsSet(128, subnetBits));
                IPAddress lIPNet2 = address2.GetNetworkAddress(IPAddressFromBitsSet(128, subnetBits));

                return lIPNet1.Equals(lIPNet2);
            }
            else
                return address1.Equals(address2);
        }
開發者ID:jogibear9988,項目名稱:ManagedUPnP,代碼行數:28,代碼來源:IPAddressExtensions.cs

示例4: IsInSameSubnet

        public static bool IsInSameSubnet(this IPAddress address2, IPAddress address, IPAddress subnetMask)
        {
            try
            {
                if (address.ToString().Contains(".") && address2.ToString().Contains(".") && subnetMask.ToString().Contains("."))
                {
                    IPAddress network1 = address.GetNetworkAddress(subnetMask);
                    IPAddress network2 = address2.GetNetworkAddress(subnetMask);

                    return network1.Equals(network2);
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                return false;
            }

        }
開發者ID:yl10030270,項目名稱:ProxyUtils,代碼行數:23,代碼來源:IPAddressExtensions.cs

示例5: IsInSameIpv4Subnet

        public static bool IsInSameIpv4Subnet(this IPAddress address2, IPAddress address, IPAddress subnetMask)
        {
            if (address2.AddressFamily != AddressFamily.InterNetwork || address.AddressFamily != AddressFamily.InterNetwork)
            {
                throw new ArgumentException("Both IPAddress must be IPV4 addresses");
            }
            var network1 = address.GetNetworkAddress(subnetMask);
            var network2 = address2.GetNetworkAddress(subnetMask);

            return network1.Equals(network2);
        }
開發者ID:JonCanning,項目名稱:ServiceStack,代碼行數:11,代碼來源:IPAddressExtensions.cs

示例6: IsInSameNetworkAs

        public static bool IsInSameNetworkAs(
            this IPAddress firstAddress,
            IPAddress secondAddress,
            IPAddress mask)
        {
            Contract.Requires<ArgumentNullException>(firstAddress != null);
            Contract.Requires<ArgumentNullException>(secondAddress != null);
            Contract.Requires<ArgumentNullException>(mask != null);

            return
                firstAddress
                .GetNetworkAddress(mask)
                .Equals(
                    secondAddress
                    .GetNetworkAddress(mask));
        }
開發者ID:kappa7194,項目名稱:ip-address-extensions,代碼行數:16,代碼來源:IPAddressExtensions.cs

示例7: IsIp6Match

        private static bool? IsIp6Match(string domain, IPAddress ipAddress, int? prefix6)
        {
            if (prefix6.HasValue)
            {
                ipAddress = ipAddress.GetNetworkAddress(prefix6.Value);
            }

            DnsMessage dnsMessage = DnsClient.Default.Resolve(domain, RecordType.Aaaa);
            if ((dnsMessage == null) || ((dnsMessage.ReturnCode != ReturnCode.NoError) && (dnsMessage.ReturnCode != ReturnCode.NxDomain)))
                return null;

            foreach (AaaaRecord dnsRecord in dnsMessage.AnswerRecords.Where(record => record.RecordType == RecordType.Aaaa).Cast<AaaaRecord>())
            {
                if (prefix6.HasValue)
                {
                    if (ipAddress.Equals(dnsRecord.Address.GetNetworkAddress(prefix6.Value)))
                        return true;
                }
                else
                {
                    if (ipAddress.Equals(dnsRecord.Address))
                        return true;
                }
            }

            return false;
        }
開發者ID:martindevans,項目名稱:Hellequin-p2p-dns,代碼行數:27,代碼來源:SpfTerm.cs

示例8: IsInSameSubnet

 internal static bool IsInSameSubnet(this IPAddress address2, IPAddress address, IPAddress subnetMask)
 {
     IPAddress networkAddress = address.GetNetworkAddress(subnetMask);
     IPAddress address4 = address2.GetNetworkAddress(subnetMask);
     return networkAddress.Equals(address4);
 }
開發者ID:PingTrip,項目名稱:PT-Sguil,代碼行數:6,代碼來源:IPAddressExtensions.cs


注:本文中的System.Net.IPAddress.GetNetworkAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。