GeoIP Module
A Module to look up the country of a given IP address. There are several providers which can be used. The most basic resolve based on the Internet Service Provider's location.
Installation
Install the package via NuGet:
dotnet add package Confinity.GeoIP
Usage
Register the module in Confinity.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddConfinity(builder, confinityOptions, moduleBuilder =>
{
moduleBuilder.AddModule<GeoIPModule>();
});
Get country by IP:
public sealed class ExampleService(IGeoIP geoIp, IHttpContextAccessor httpContextAccessor)
{
public async Task InvokeAsync()
{
var remoteIpAddress = httpContextAccessor.HttpContext?.Connection.RemoteIpAddress;
var country = await geoIp.GetCountryAsync(remoteIpAddress);