2020-07-17 01:05:25 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-07-17 02:52:36 +00:00
|
|
|
"bufio"
|
2020-07-17 01:05:25 +00:00
|
|
|
"fmt"
|
2020-07-17 01:41:09 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2020-07-17 01:05:25 +00:00
|
|
|
|
|
|
|
"github.com/zu1k/nali/internal/app"
|
2020-07-17 05:49:11 +00:00
|
|
|
"github.com/zu1k/nali/internal/ipdb"
|
2020-07-17 01:05:25 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "nali",
|
2020-07-17 05:49:11 +00:00
|
|
|
Short: "An offline tool for querying IP geographic information",
|
|
|
|
Long: `An offline tool for querying IP geographic information.`,
|
2020-07-17 02:52:36 +00:00
|
|
|
Args: cobra.MinimumNArgs(0),
|
2020-07-17 01:05:25 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-07-17 04:12:04 +00:00
|
|
|
app.InitIPDB(ipdb.GetIPDBType())
|
2020-07-17 01:05:25 +00:00
|
|
|
if len(args) == 0 {
|
2020-07-17 02:52:36 +00:00
|
|
|
stdin := bufio.NewScanner(os.Stdin)
|
|
|
|
for stdin.Scan() {
|
|
|
|
line := stdin.Text()
|
|
|
|
if line == "quit" || line == "exit" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(app.ReplaceInString(line))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
app.ParseIPs(args)
|
2020-07-17 01:05:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-17 01:55:24 +00:00
|
|
|
// Execute parse subcommand and run
|
2020-07-17 01:05:25 +00:00
|
|
|
func Execute() {
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
2020-07-17 01:41:09 +00:00
|
|
|
log.Fatal(err.Error())
|
|
|
|
os.Exit(1)
|
2020-07-17 01:05:25 +00:00
|
|
|
}
|
|
|
|
}
|