当前位置: 首页>>代码示例>>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;未经允许,请勿转载。