Files
Flypaper/src/Flypaper.GeoIp/MaxMindGeoIpDatabase.cs
T
TomandClaude Opus 5.5 3671019e60
Build and deploy / build (push) Successful in 1m46s
Build and deploy / deploy (push) Successful in 22s
Add IP origin enrichment with DB-IP and world map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:44:33 +01:00

36 lines
919 B
C#

using System.Net;
using Flypaper.Core.Models;
using MaxMind.GeoIP2;
using MaxMind.GeoIP2.Responses;
namespace Flypaper.GeoIp;
internal sealed class MaxMindGeoIpDatabase(DatabaseReader? city, DatabaseReader? asn) : IGeoIpDatabase
{
public IpOrigin? Find(IPAddress address)
{
CityResponse? cityResponse = null;
AsnResponse? asnResponse = null;
city?.TryCity(address, out cityResponse);
asn?.TryAsn(address, out asnResponse);
if (cityResponse is null && asnResponse is null)
{
return null;
}
return new IpOrigin(
cityResponse?.Country.IsoCode,
cityResponse?.Country.Name,
cityResponse?.City.Name,
asnResponse?.AutonomousSystemNumber,
asnResponse?.AutonomousSystemOrganization);
}
public void Dispose()
{
city?.Dispose();
asn?.Dispose();
}
}