Ejemplo n.º 1
0
        /// <summary>
        /// Checks the given IP against the black list
        /// </summary>
        /// <param name="address">The IP to check</param>
        /// <returns>An object representing the blacklist status and any applicable matches</returns>
        public BlacklistStatus CheckIP(IPAddress address)
        {
            if (address is null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            BigInteger toCheck = IPRegistration.IpToInt(address);

            BlacklistStatus toReturn = new BlacklistStatus();

            if (!(this.BlackList?.IsLoaded ?? false))
            {
                toReturn.State = BlacklistState.NotLoaded;
            }
            else
            {
                toReturn.State = BlacklistState.Pass;

                foreach (IPAnalysis analysis in this.BlackList.Analysis)
                {
                    if (analysis.IsMatch(toCheck))
                    {
                        toReturn.Matches.Add(analysis);
                        toReturn.State = BlacklistState.Fail;
                    }
                }
            }

            return(toReturn);
        }
Ejemplo n.º 2
0
        public static bool IsBlacklisted(IPAddress Ip)
        {
            if (IPRegistrations != null)
            {
                foreach (IIPRegistration iPRegistration in IPRegistrations)
                {
                    if (iPRegistration.IsMatch(IPRegistration.IpToInt(Ip)))
                    {
                        return(true);
                    }
                }
            }

            _ = QueryIP(Ip);

            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Checks if the given IP is described by this analysis
 /// </summary>
 /// <param name="IPAddress">The IP to check</param>
 /// <returns>If the IP is represented by this analysis</returns>
 public bool IsMatch(System.Net.IPAddress IPAddress)
 {
     return(IPAddress is null ? throw new ArgumentNullException(nameof(IPAddress)) : this.IsMatch(IPRegistration.IpToInt(IPAddress)));
 }