Fixed command and added new command

Fixed search command and added init command.
This commit is contained in:
perp 2023-08-12 00:22:48 +01:00
parent 433a0c3f64
commit 552c98c684
2 changed files with 33 additions and 37 deletions

View File

@ -0,0 +1,25 @@
package commands
import (
"github.com/spf13/cobra"
"git.tcp.direct/perp/shogo/internal/shodan"
"git.tcp.direct/perp/shogo/internal/utils"
)
// Init command
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize Shogo",
Example: "init <key>",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
utils.CheckColor()
// Create flags & pool
flags := &shodan.Flags{
Args: args,
}
shodan.Pool("init", flags, nil, nil)
},
}

View File

@ -1,10 +1,6 @@
package commands
import (
"fmt"
"os"
"github.com/panjf2000/ants/v2"
"github.com/spf13/cobra"
"git.tcp.direct/perp/shogo/internal/shodan"
@ -27,40 +23,15 @@ var searchCmd = &cobra.Command{
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)
// Create flags & pool
flags := &shodan.Flags{
Args: args,
Fields: fields,
Separator: separator,
Pages: pages,
Page: 1,
}
defer pool.Release()
// Query each page
for p := 1; p <= pages; p++ {
search := &shodan.Search{
Query: args[0],
Page: p,
Fields: fields,
Separator: separator,
Results: results,
}
pool.Submit(func() {
go search.Search()
})
}
// Get page result
for j := 1; j <= pages*100; j++ {
result := <-results
if result != "" {
fmt.Println(result)
}
}
defer close(results)
shodan.Pool("search", flags, nil, nil)
},
}