✨ Fixed command and added new command
Fixed search command and added init command.
This commit is contained in:
parent
433a0c3f64
commit
552c98c684
25
cmd/shogo/commands/init.go
Normal file
25
cmd/shogo/commands/init.go
Normal 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)
|
||||||
|
},
|
||||||
|
}
|
@ -1,10 +1,6 @@
|
|||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/panjf2000/ants/v2"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"git.tcp.direct/perp/shogo/internal/shodan"
|
"git.tcp.direct/perp/shogo/internal/shodan"
|
||||||
@ -27,40 +23,15 @@ var searchCmd = &cobra.Command{
|
|||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
utils.CheckColor()
|
utils.CheckColor()
|
||||||
|
|
||||||
// Results channel
|
// Create flags & pool
|
||||||
results := make(chan string)
|
flags := &shodan.Flags{
|
||||||
|
Args: args,
|
||||||
// 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++ {
|
|
||||||
search := &shodan.Search{
|
|
||||||
Query: args[0],
|
|
||||||
Page: p,
|
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
Separator: separator,
|
Separator: separator,
|
||||||
Results: results,
|
Pages: pages,
|
||||||
|
Page: 1,
|
||||||
}
|
}
|
||||||
|
shodan.Pool("search", flags, nil, nil)
|
||||||
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)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user