oschwald / geoip2-golang

Unofficial MaxMind GeoIP2 Reader for Go
ISC License
1.86k stars 191 forks source link

For GeoLite2-ASN.mmdb: query organization name with known ASN #89

Closed ojdo closed 2 years ago

ojdo commented 2 years ago

Currenty I only retrieve the AutonomousSystemNumber uint at one point in a longer date pipeline which aggregates over multiple IPs. Is there a "decent" way to query the database with the above number and return the corresponding AutonomousSystemOrganization string?

I would be fine with just iterating over the whole file, but so far I only could identify the Networks-oriented traverse functionality.

Is there an elegant way to accomplish this?

oschwald commented 2 years ago

No, there isn't a way to query by ASN. The database is only indexed by IP address. As you suggest, you can use the Networks function to (inefficiently) create such a map yourself using something like db.Networks(maxminddb.SkipAliasedNetworks).