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:
parent
e421b357fd
commit
57b92a557e
34
X10D/src/Net/IpAddressExtensions.cs
Normal file
34
X10D/src/Net/IpAddressExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user