public static IPNet Parse(string ip, string subnet) { if (IPAddress.TryParse(ip, out var ipAddr)) { if (IPAddress.TryParse(subnet, out var subnetAddr)) { if (!TinyIPAddress.FromIPAddress(subnetAddr).Value.IsValidSubnet) { throw new IPNetParseException("Error parsing subnet mask Address from IP: '" + subnet + "' is not a valid subnet"); } return(new IPNet(ipAddr, subnetAddr)); } throw new IPNetParseException("Error parsing subnet mask from IP: '" + subnet + "'"); } throw new IPNetParseException("Error parsing IP Address from IP: '" + ip + "'"); }
public static IPNet Parse(string ip, string subnet) { IPAddress ipAddr, subnetAddr; if (IPAddress.TryParse(ip, out ipAddr)) { if (IPAddress.TryParse(subnet, out subnetAddr)) { if (!TinyIPAddress.FromIPAddress(subnetAddr).Value.IsValidSubnet) { throw new IPNetParseException("Error parsing subnet mask Address from IP: '{0}' is not a valid subnet", subnet); } return(new IPNet(ipAddr, subnetAddr)); } throw new IPNetParseException("Error parsing subnet mask from IP: '{0}'", subnet); } throw new IPNetParseException("Error parsing IP Address from IP: '{0}'", ip); }