public bool Contains(IPAddress ip) { if (AddressFamily != ip.AddressFamily) { return(false); } var tip = TinyIPAddress.FromIPAddress(ip); return(tip.HasValue && Contains(tip.Value)); }
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); }
private bool Contains(TinyIPAddress tip) => AddressFamily == tip.AddressFamily && (TSubnet & TIPAddress) == (TSubnet & tip);
private bool Contains(TinyIPAddress tip) { return (AddressFamily == tip.AddressFamily && (TSubnet & TIPAddress) == (TSubnet & tip)); }