ooni-probe-cli/internal/cli/geoip/geoip.go

42 lines
857 B
Go
Raw Normal View History

2018-03-23 12:10:14 +01:00
package geoip
import (
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/ooni/probe-cli/internal/cli/root"
2018-06-22 14:25:30 +02:00
"github.com/ooni/probe-cli/internal/output"
2018-03-23 12:10:14 +01:00
)
func init() {
cmd := root.Command("geoip", "Perform a geoip lookup")
cmd.Action(func(_ *kingpin.ParseContext) error {
2018-06-22 14:25:30 +02:00
output.SectionTitle("GeoIP lookup")
probeCLI, err := root.Init()
2018-03-23 12:10:14 +01:00
if err != nil {
return err
}
engine, err := probeCLI.NewProbeEngine()
if err != nil {
return err
}
defer engine.Close()
err = engine.MaybeLookupLocation()
2018-03-23 12:10:14 +01:00
if err != nil {
return err
}
log.WithFields(log.Fields{
2018-06-22 14:25:30 +02:00
"type": "table",
"asn": engine.ProbeASNString(),
"network_name": engine.ProbeNetworkName(),
"country_code": engine.ProbeCC(),
"ip": engine.ProbeIP(),
2018-03-23 12:10:14 +01:00
}).Info("Looked up your location")
return nil
})
}