44 lines
792 B
Go
44 lines
792 B
Go
|
package shodan
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/ns3777k/go-shodan/v4/shodan"
|
||
|
|
||
|
"git.tcp.direct/perp/shogo/internal/utils"
|
||
|
)
|
||
|
|
||
|
// Stats query
|
||
|
type Stats struct {
|
||
|
Query string // Search query
|
||
|
Page int // Current page
|
||
|
Results chan string // Results channel
|
||
|
}
|
||
|
|
||
|
// Return facet stats on a search
|
||
|
func (s *Stats) Stats() {
|
||
|
// Setup options
|
||
|
options := &shodan.HostQueryOptions{
|
||
|
Query: s.Query,
|
||
|
Facets: "US",
|
||
|
Page: s.Page,
|
||
|
}
|
||
|
|
||
|
// Get results
|
||
|
results, err := utils.Client.GetHostsForQuery(context.Background(), options)
|
||
|
if err != nil {
|
||
|
fmt.Printf("%s: %s\n", utils.Red("Error"), err.Error())
|
||
|
s.Results <- ""
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Print results
|
||
|
for host := range results.Matches {
|
||
|
fmt.Println(results.Matches[host])
|
||
|
}
|
||
|
s.Results <- ""
|
||
|
}
|
||
|
|
||
|
// Todo: Fix this
|