1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 04:55:42 +00:00

Add IPAddress.IsIpv4/6

This commit is contained in:
Oliver Booth 2022-04-21 21:52:37 +01:00
parent e421b357fd
commit 57b92a557e
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634

View File

@ -0,0 +1,34 @@
using System.Net;
using System.Net.Sockets;
namespace X10D.Net;
/// <summary>
/// Extension methods for <see cref="IPAddress" />.
/// </summary>
public static class IpAddressExtensions
{
/// <summary>
/// Returns a value indicating whether the specified IP address is a valid IPv4 address.
/// </summary>
/// <param name="address">The IP address to check.</param>
/// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv4 address; otherwise, <see langword="false" />.
/// </returns>
public static bool IsIpV4(this IPAddress address)
{
return address.AddressFamily == AddressFamily.InterNetwork;
}
/// <summary>
/// Returns a value indicating whether the specified IP address is a valid IPv6 address.
/// </summary>
/// <param name="address">The IP address to check.</param>
/// <returns>
/// <see langword="true" /> if the specified IP address is a valid IPv6 address; otherwise, <see langword="false" />.
/// </returns>
public static bool IsIpV6(this IPAddress address)
{
return address.AddressFamily == AddressFamily.InterNetworkV6;
}
}