From 57b92a557eb9b5ca2b9afe0429e86aa9551e2774 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 21 Apr 2022 21:52:37 +0100 Subject: [PATCH] Add IPAddress.IsIpv4/6 --- X10D/src/Net/IpAddressExtensions.cs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 X10D/src/Net/IpAddressExtensions.cs 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; + } +}