diff --git a/X10D/src/Net/IpAddressExtensions.cs b/X10D/src/Net/IpAddressExtensions.cs new file mode 100644 index 0000000..12d0971 --- /dev/null +++ b/X10D/src/Net/IpAddressExtensions.cs @@ -0,0 +1,34 @@ +using System.Net; +using System.Net.Sockets; + +namespace X10D.Net; + +/// +/// Extension methods for . +/// +public static class IpAddressExtensions +{ + /// + /// Returns a value indicating whether the specified IP address is a valid IPv4 address. + /// + /// The IP address to check. + /// + /// if the specified IP address is a valid IPv4 address; otherwise, . + /// + public static bool IsIpV4(this IPAddress address) + { + return address.AddressFamily == AddressFamily.InterNetwork; + } + + /// + /// Returns a value indicating whether the specified IP address is a valid IPv6 address. + /// + /// The IP address to check. + /// + /// if the specified IP address is a valid IPv6 address; otherwise, . + /// + public static bool IsIpV6(this IPAddress address) + { + return address.AddressFamily == AddressFamily.InterNetworkV6; + } +}