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

42 lines
829 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")
2018-03-23 12:10:14 +01:00
ctx, err := root.Init()
if err != nil {
return err
}
sess, err := ctx.NewSession()
if err != nil {
return err
}
defer sess.Close()
err = sess.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": sess.ProbeASNString(),
"network_name": sess.ProbeNetworkName(),
"country_code": sess.ProbeCC(),
"ip": sess.ProbeIP(),
2018-03-23 12:10:14 +01:00
}).Info("Looked up your location")
return nil
})
}