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
|
|
|
|
}
|
|
|
|
|
2020-06-04 11:19:38 +02:00
|
|
|
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",
|
2020-06-04 11:19:38 +02:00
|
|
|
"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
|
|
|
|
})
|
|
|
|
}
|