Use ooni/probe-engine: episode 1 (#42)

This commit is contained in:
Simone Basso
2019-05-23 16:38:46 +02:00
committed by GitHub
parent eb4fec2f21
commit df629237be
15 changed files with 147 additions and 322 deletions
+5 -19
View File
@@ -1,20 +1,15 @@
package geoip
import (
"fmt"
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/output"
"github.com/ooni/probe-cli/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 {
output.SectionTitle("GeoIP lookup")
ctx, err := root.Init()
@@ -22,26 +17,17 @@ func init() {
return err
}
if err = ctx.MaybeDownloadDataFiles(); err != nil {
log.WithError(err).Error("failed to download data files")
}
geoipPath := utils.GeoIPDir(ctx.Home)
if *shouldUpdate {
utils.DownloadGeoIPDatabaseFiles(geoipPath)
}
loc, err := utils.GeoIPLookup(geoipPath)
err = ctx.MaybeLocationLookup()
if err != nil {
return err
}
log.WithFields(log.Fields{
"type": "table",
"asn": fmt.Sprintf("AS%d", loc.ASN),
"network_name": loc.NetworkName,
"country_code": loc.CountryCode,
"ip": loc.IP,
"asn": ctx.Session.ProbeASNString(),
"network_name": ctx.Session.ProbeNetworkName(),
"country_code": ctx.Session.ProbeCC(),
"ip": ctx.Session.ProbeIP(),
}).Info("Looked up your location")
return nil