From 70e45b270c6e58eb600765f2b0af6b5bf6688e4b Mon Sep 17 00:00:00 2001 From: perp Date: Wed, 2 Aug 2023 04:57:31 +0100 Subject: [PATCH] :sparkles: Stats command Added stats command (Broken) --- cmd/shogo/commands/stats.go | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 cmd/shogo/commands/stats.go diff --git a/cmd/shogo/commands/stats.go b/cmd/shogo/commands/stats.go new file mode 100644 index 0000000..1aa3361 --- /dev/null +++ b/cmd/shogo/commands/stats.go @@ -0,0 +1,55 @@ +package commands + +import ( + "fmt" + "os" + + "github.com/panjf2000/ants/v2" + "github.com/spf13/cobra" + + "git.tcp.direct/perp/shogo/internal/shodan" + "git.tcp.direct/perp/shogo/internal/utils" +) + +// Stats command +var statsCmd = &cobra.Command{ + Use: "stats", + Short: "Return facet stats on a search", + Example: "stats \nstats ...", + Run: func(_ *cobra.Command, args []string) { + utils.CheckColor() + + // Results channel + results := make(chan string) + + // Goroutine pool + pool, err := ants.NewPool(threads) + if err != nil { + fmt.Printf("%s: %s\n", utils.Red("Error"), err.Error()) + os.Exit(1) + } + defer pool.Release() + + // Query each page + for p := 1; p <= pages; p++ { + stats := &shodan.Stats{ + Query: args[0], + Page: p, + Results: results, + } + + pool.Submit(func() { + go stats.Stats() + }) + } + + // Get page result + for j := 1; j <= pages*100; j++ { + result := <-results + if result != "" { + fmt.Println(result) + } + } + defer close(results) + }, +}