Kenc.AbuseIPDB 1.0.17

dotnet add package Kenc.AbuseIPDB --version 1.0.17
NuGet\Install-Package Kenc.AbuseIPDB -Version 1.0.17
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kenc.AbuseIPDB" Version="1.0.17" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kenc.AbuseIPDB --version 1.0.17
#r "nuget: Kenc.AbuseIPDB, 1.0.17"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.0.17 539 1/10/2023
1.0.13 565 11/15/2021
1.0.6-beta 347 7/12/2021
0.3.602.2 493 6/2/2021
0.1.405.7 331 4/5/2021
0.1.102.6 482 1/2/2021