Beispiel #1
0
        public bool Contains(IPAddress ip)
        {
            if (AddressFamily != ip.AddressFamily)
            {
                return(false);
            }
            var tip = TinyIPAddress.FromIPAddress(ip);

            return(tip.HasValue && Contains(tip.Value));
        }
Beispiel #2
0
 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 + "'");
 }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 private bool Contains(TinyIPAddress tip) =>
 AddressFamily == tip.AddressFamily && (TSubnet & TIPAddress) == (TSubnet & tip);
Beispiel #5
0
 private bool Contains(TinyIPAddress tip)
 {
     return
         (AddressFamily == tip.AddressFamily &&
          (TSubnet & TIPAddress) == (TSubnet & tip));
 }