示例#1
0
        /// <summary>
        /// Tries to ban an IP explicitly.
        /// </summary>
        /// <param name="address">The IP address to ban.</param>
        /// <param name="banUntil">A <see cref="DateTime" /> specifying the expiration time of the ban.</param>
        /// <param name="baseRoute">The base route.</param>
        /// <param name="isExplicit"><c>true</c> if the IP was explicitly banned.</param>
        /// <returns>
        ///   <c>true</c> if the IP was added to the blacklist; otherwise, <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentException">baseRoute</exception>
        public static bool TryBanIP(IPAddress address, DateTime banUntil, string baseRoute = "/", bool isExplicit = true)
        {
            if (!IPBanningExecutor.TryGetInstance(baseRoute, out var instance))
            {
                throw new ArgumentException(NoConfigurationFound, nameof(baseRoute));
            }

            return(instance.TryBanIP(address, isExplicit, banUntil));
        }
示例#2
0
 /// <summary>
 /// Gets the list of current banned IPs.
 /// </summary>
 /// <param name="baseRoute">The base route.</param>
 /// <returns>
 /// A collection of <see cref="BanInfo" /> in the blacklist.
 /// </returns>
 /// <exception cref="ArgumentException">baseRoute</exception>
 public static IEnumerable <BanInfo> GetBannedIPs(string baseRoute = "/")
 => IPBanningExecutor.TryGetInstance(baseRoute, out var instance)
         ? instance.BlackList
         : throw new ArgumentException(NoConfigurationFound, nameof(baseRoute));
示例#3
0
 /// <summary>
 /// Tries to unban an IP explicitly.
 /// </summary>
 /// <param name="address">The IP address.</param>
 /// <param name="baseRoute">The base route.</param>
 /// <returns>
 ///   <c>true</c> if the IP was removed from the blacklist; otherwise, <c>false</c>.
 /// </returns>
 /// <exception cref="ArgumentException">baseRoute</exception>
 public static bool TryUnbanIP(IPAddress address, string baseRoute = "/")
 => IPBanningExecutor.TryGetInstance(baseRoute, out var instance)
         ? instance.TryRemoveBlackList(address)
         : throw new ArgumentException(NoConfigurationFound, nameof(baseRoute));