AcManager.Tools.Helpers.IPAddressExtension.GetSubnetMask C# (CSharp) Method

GetSubnetMask() public static method

public static GetSubnetMask ( this address ) : IPAddress
address this
return System.Net.IPAddress
        public static IPAddress GetSubnetMask(this IPAddress address) {
            foreach (var addressInformation in from networkInterface in NetworkInterfaces
                                               from addressInformation in networkInterface.GetIPProperties().UnicastAddresses
                                               where addressInformation.Address.AddressFamily == AddressFamily.InterNetwork &&
                                                       address.Equals(addressInformation.Address)
                                               select addressInformation) {
                return addressInformation.IPv4Mask;
            }

            throw new Exception($"Can’t find subnetmask for IP address '{address}'");
        }
    }