Unify and improve country info

This commit is contained in:
Daniel
2023-08-28 15:26:12 +02:00
parent a2c24f131a
commit 28a4ea4709
8 changed files with 857 additions and 1290 deletions

View File

@@ -251,7 +251,7 @@ func (e *Entity) getLocation(ctx context.Context) {
return
}
e.location = loc
e.Country = loc.Country.ISOCode
e.Country = loc.Country.Code
e.Coordinates = &loc.Coordinates
e.ASN = loc.AutonomousSystemNumber
e.ASOrg = loc.AutonomousSystemOrganization
@@ -272,9 +272,10 @@ func (e *Entity) getLocation(ctx context.Context) {
// Log location
log.Tracer(ctx).Tracef(
"intel: located %s in %s (AS%d by %s)%s",
"intel: located %s in %s (%s), as part of AS%d by %s%s",
e.IP,
loc.Country.ISOCode,
loc.Country.Name,
loc.Country.Code,
loc.AutonomousSystemNumber,
loc.AutonomousSystemOrganization,
flags,
@@ -303,6 +304,16 @@ func (e *Entity) GetCountry(ctx context.Context) (string, bool) {
return e.Country, true
}
// GetCountryInfo returns the two letter ISO country code and whether it is set.
func (e *Entity) GetCountryInfo(ctx context.Context) *geoip.CountryInfo {
e.getLocation(ctx)
if e.LocationError != "" {
return nil
}
return &e.location.Country
}
// GetASN returns the AS number and whether it is set.
func (e *Entity) GetASN(ctx context.Context) (uint, bool) {
e.getLocation(ctx)