Class IPBanningModule
A module to ban clients by IP address, based on TCP requests-per-second or RegEx matches on log messages.
Inherited Members
Namespace: EmbedIO.Security
Syntax
public class IPBanningModule : WebModuleBase, IWebModuleImpl, IWebModule, IDisposable
Constructors
IPBanningModule(String, Nullable<IEnumerable<String>>, Int32)
Initializes a new instance of the IPBanningModule class.
Declaration
public IPBanningModule(string baseRoute = "/", IEnumerable<string>? whitelist = default(IEnumerable<string>? ), int banMinutes = 30)
Parameters
Type | Name | Description |
---|---|---|
String | baseRoute | The base route. |
Nullable<IEnumerable<String>> | whitelist | A collection of valid IPs that never will be banned. |
Int32 | banMinutes | Minutes that an IP will remain banned. |
Fields
DefaultBanMinutes
The default ban minutes.
Declaration
public const int DefaultBanMinutes = 30
Field Value
Type | Description |
---|---|
Int32 |
Properties
ClientAddress
Gets the client address.
Declaration
public IPAddress? ClientAddress { get; }
Property Value
Type | Description |
---|---|
Nullable<IPAddress> | The client address. |
IsFinalHandler
Gets a value indicating whether processing of a request should stop after a module has handled it.
Declaration
public override bool IsFinalHandler { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
Remarks
If this property is true, a HTTP context's
SetHandled() method will be automatically called
immediately after after the
See Also
Methods
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Releases unmanaged and - optionally - managed resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing |
|
Finalize()
Finalizes an instance of the IPBanningModule class.
Declaration
protected void Finalize()
GetBannedIPs(String)
Gets the list of current banned IPs.
Declaration
public static IEnumerable<BanInfo> GetBannedIPs(string baseRoute = "/")
Parameters
Type | Name | Description |
---|---|---|
String | baseRoute | The base route. |
Returns
Type | Description |
---|---|
IEnumerable<BanInfo> | A collection of BanInfo in the blacklist. |
OnRequestAsync(IHttpContext)
Called to handle a request from a client.
Declaration
protected override Task OnRequestAsync(IHttpContext context)
Parameters
Type | Name | Description |
---|---|---|
IHttpContext | context | The context of the request being handled. |
Returns
Type | Description |
---|---|
Task | A |
Overrides
OnStart(CancellationToken)
Called when a module is started, immediately before locking the module's configuration.
Declaration
protected override void OnStart(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A |
Overrides
RegisterCriterion(IIPBanningCriterion)
Registers the criterion.
Declaration
public void RegisterCriterion(IIPBanningCriterion criterion)
Parameters
Type | Name | Description |
---|---|---|
IIPBanningCriterion | criterion | The criterion. |
TryBanIP(IPAddress, DateTime, String, Boolean)
Tries to ban an IP explicitly.
Declaration
public static bool TryBanIP(IPAddress address, DateTime banUntil, string baseRoute = "/", bool isExplicit = true)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | address | The IP address to ban. |
DateTime | banUntil | A |
String | baseRoute | The base route. |
Boolean | isExplicit |
|
Returns
Type | Description |
---|---|
Boolean |
|
TryBanIP(IPAddress, Int32, String, Boolean)
Tries to ban an IP explicitly.
Declaration
public static bool TryBanIP(IPAddress address, int banMinutes, string baseRoute = "/", bool isExplicit = true)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | address | The IP address to ban. |
Int32 | banMinutes | Minutes that the IP will remain banned. |
String | baseRoute | The base route. |
Boolean | isExplicit |
|
Returns
Type | Description |
---|---|
Boolean |
|
TryBanIP(IPAddress, TimeSpan, String, Boolean)
Tries to ban an IP explicitly.
Declaration
public static bool TryBanIP(IPAddress address, TimeSpan banDuration, string baseRoute = "/", bool isExplicit = true)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | address | The IP address to ban. |
TimeSpan | banDuration | A |
String | baseRoute | The base route. |
Boolean | isExplicit |
|
Returns
Type | Description |
---|---|
Boolean |
|
TryUnbanIP(IPAddress, String)
Tries to unban an IP explicitly.
Declaration
public static bool TryUnbanIP(IPAddress address, string baseRoute = "/")
Parameters
Type | Name | Description |
---|---|---|
IPAddress | address | The IP address. |
String | baseRoute | The base route. |
Returns
Type | Description |
---|---|
Boolean |
|