Kenc.AbuseIPDB
1.0.17
dotnet add package Kenc.AbuseIPDB --version 1.0.17
NuGet\Install-Package Kenc.AbuseIPDB -Version 1.0.17
<PackageReference Include="Kenc.AbuseIPDB" Version="1.0.17" />
paket add Kenc.AbuseIPDB --version 1.0.17
#r "nuget: Kenc.AbuseIPDB, 1.0.17"
// Install Kenc.AbuseIPDB as a Cake Addin #addin nuget:?package=Kenc.AbuseIPDB&version=1.0.17 // Install Kenc.AbuseIPDB as a Cake Tool #tool nuget:?package=Kenc.AbuseIPDB&version=1.0.17
About
Kenc.AbuseIPDB is a fully featured client for connecting with the AbuseIPDB.com API v2.
How to use
Kenc.AbuseIPDb is built with dependency-injection as a first-class-citizen. As a result, there's a helper function to register the library including pointing to the configuration section, if IConfiguration is being utilized.
Configuration:
"AbuseIPDB": {
"APIEndpoint": "https://api.abuseipdb.com/api/v2/",
"APIKey": "<apikey>"
}
API key should be loaded from a secure storage, such as keyvault to prevent leaks.
services.AddAbuseIPDBClient(Configuration.GetSection("AbuseIPDB"));
...
public HomeController(ILogger<BlogController> logger, IAbuseIPDBClient abuseIPDBClient, IHttpContextAccessor httpContextAccessor)
To lookup the requester IP of a request in ASP.net and reject IPs with an abuse confidence score of 70 or higher:
var ip = httpContextAccessor.HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress;
try
{
// skip for local loopback
if (!IPAddress.IsLoopback(ip))
{
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
(Check abuseCheck, _) = await abuseIPDBClient.CheckAsync(ip.ToString(), 90, false, cancellationTokenSource.Token);
if (abuseCheck.AbuseConfidenceScore > 70)
{
var error = new ErrorModel
{
Title = "Bad Request.",
Detail = "User IP is blocked due to abuse.",
Instance = $"/action/{Activity.Current?.Id ?? httpContextAccessor.HttpContext.TraceIdentifier}",
Status = 400,
Type = "/action/abusiveip"
};
// return a 400 with the error information
return Unauthorized(error);
}
}
}
catch (OperationCanceledException)
{
// request timed out.
}
catch (ApiException abuseIPException)
{
// abuse ip db threw an exception
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Http (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
- System.Net.Http.Json (>= 7.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Kenc.AbuseIPDB:
Package | Downloads |
---|---|
Kenc.AbuseIPDB.Cache
Cache for Kenc.AbuseIPDB based on LazyCache. |
GitHub repositories
This package is not used by any popular GitHub repositories.