2018-03-23 12:10:14 +01:00
|
|
|
package geoip
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/alecthomas/kingpin"
|
|
|
|
"github.com/apex/log"
|
2018-05-03 14:59:55 +02:00
|
|
|
"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")
|
2018-03-23 12:10:14 +01:00
|
|
|
ctx, err := root.Init()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-05-23 16:38:46 +02:00
|
|
|
err = ctx.MaybeLocationLookup()
|
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",
|
2019-05-23 16:38:46 +02:00
|
|
|
"asn": ctx.Session.ProbeASNString(),
|
|
|
|
"network_name": ctx.Session.ProbeNetworkName(),
|
|
|
|
"country_code": ctx.Session.ProbeCC(),
|
|
|
|
"ip": ctx.Session.ProbeIP(),
|
2018-03-23 12:10:14 +01:00
|
|
|
}).Info("Looked up your location")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|