public static bool IsValidNetmask(string sNetmask) { IPAddress netmask; if (IPAddress.TryParse(sNetmask, out netmask) && (netmask.AddressFamily == AddressFamily.InterNetwork)) { return(IPNetwork.ValidNetmask(netmask)); } return(false); }
public static bool IsWildCardNetmask(string sMask) { IPAddress netmask; if (IPAddress.TryParse(sMask, out netmask) && (netmask.AddressFamily == AddressFamily.InterNetwork)) { UInt32 maskInNumber = ~Ip2Number(sMask); string wildcardMask = Number2Ip(maskInNumber); IPAddress wildmask; IPAddress.TryParse(wildcardMask, out wildmask); return(IPNetwork.ValidNetmask(wildmask)); } return(false); }
private static bool IsValidNetmask(String sNetmask, AddressFamily[] allowedAddressFamilies) { if (allowedAddressFamilies == null || allowedAddressFamilies.Length == 0) { return(false); } IPAddress netmask = null; if (IPAddress.TryParse(sNetmask, out netmask) && Array.Exists(allowedAddressFamilies, e => e == netmask.AddressFamily)) { return(IPNetwork.ValidNetmask(netmask)); } return(false); }