本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}