ooni-probe-cli/internal/cli/geoip/geoip.go
Arturo Filastò 749cc665af Add support for downloading legacy geoip databases
Pass the geoip databases to measurement-kit
2018-03-23 15:26:25 +01:00

43 lines
915 B
Go

package geoip
import (
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/openobservatory/gooni/internal/cli/root"
"github.com/openobservatory/gooni/utils"
)
func init() {
cmd := root.Command("geoip", "Perform a geoip lookup")
shouldUpdate := cmd.Flag("update", "Update the geoip database").Bool()
cmd.Action(func(_ *kingpin.ParseContext) error {
log.Info("geoip")
ctx, err := root.Init()
if err != nil {
return err
}
geoipPath := utils.GeoIPDir(ctx.Home)
if *shouldUpdate {
utils.DownloadGeoIPDatabaseFiles(geoipPath)
utils.DownloadLegacyGeoIPDatabaseFiles(geoipPath)
}
loc, err := utils.GeoIPLookup(geoipPath)
if err != nil {
return err
}
log.WithFields(log.Fields{
"asn": loc.ASN,
"network_name": loc.NetworkName,
"country_code": loc.CountryCode,
"ip": loc.IP,
}).Info("Looked up your location")
return nil
})
}