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

            return(tip.HasValue && Contains(tip.Value));
        }
示例#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 + "'");
 }
示例#3
0
文件: IPNet.cs 项目: zsbfree/Opserver
        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);
        }
示例#4
0
 private bool Contains(TinyIPAddress tip) =>
 AddressFamily == tip.AddressFamily && (TSubnet & TIPAddress) == (TSubnet & tip);
示例#5
0
 private bool Contains(TinyIPAddress tip)
 {
     return
         (AddressFamily == tip.AddressFamily &&
          (TSubnet & TIPAddress) == (TSubnet & tip));
 }