Add IP origin enrichment with DB-IP and world map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
536aee1f31
commit
3671019e60
47 files changed
+1389
-12
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user