🎨 Updated code

Redid printing and commented out filtering.
This commit is contained in:
perp 2023-08-12 00:25:58 +01:00
parent 334eec2130
commit 0f5ca03bd6

View File

@ -3,7 +3,6 @@ package shodan
import ( import (
"context" "context"
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/ns3777k/go-shodan/v4/shodan" "github.com/ns3777k/go-shodan/v4/shodan"
@ -11,21 +10,12 @@ import (
"git.tcp.direct/perp/shogo/internal/utils" "git.tcp.direct/perp/shogo/internal/utils"
) )
// Search query
type Search struct {
Query string // Search query
Page int // Current page
Fields []string // Filter fields
Separator string // Filter separator
Results chan string // Results channel
}
// Return shodan search results // Return shodan search results
func (s *Search) Search() { func (s *Shodan) Search() {
// Setup options // Setup options
options := &shodan.HostQueryOptions{ options := &shodan.HostQueryOptions{
Query: s.Query, Query: s.Flags.Query,
Page: s.Page, Page: s.Flags.Page,
Minify: false, Minify: false,
} }
@ -37,11 +27,18 @@ func (s *Search) Search() {
return return
} }
// Store lines
var lines string
// More than 2 matches // More than 2 matches
if len(results.Matches) > 2 { if len(results.Matches) > 2 {
// Go through matches // Go through matches
for match := range results.Matches { for match := range results.Matches {
if len(s.Fields) != 0 { if len(s.Flags.Fields) != 0 {
lines += utils.Title.Sprintf("Filtering has not been implemented yet\n")
break
/*
fields := map[string]string{ fields := map[string]string{
"product": results.Matches[match].Product, "product": results.Matches[match].Product,
"ip_str": results.Matches[match].IP.String(), "ip_str": results.Matches[match].IP.String(),
@ -74,39 +71,57 @@ func (s *Search) Search() {
} }
} }
lines := strings.Split(content, "\n") data := strings.Split(content, "\n")
for line := range lines { for line := range data {
result += strings.TrimRight(lines[line], ":") result += strings.TrimRight(data[line], ":")
} }
// Print results // Print results
fmt.Println(result) fmt.Println(result)
*/
} else { } else {
// Send results // Send results
content := fmt.Sprintf("%s: %s\n%s: %s\n%s: %s\n", lines += fmt.Sprintf("%s: %s\n%s: %s\n%s: %s\n",
utils.Green("IP"), utils.Blue(results.Matches[match].IP.String()), utils.Green("IP"), utils.Blue(results.Matches[match].IP.String()),
utils.Blue("Port"), utils.Green(results.Matches[match].Port), utils.Blue("Port"), utils.Green(results.Matches[match].Port),
utils.Green("Hostname"), utils.Blue(strings.Join(results.Matches[0].Hostnames, ",")), utils.Green("Hostname"), utils.Blue(strings.Join(results.Matches[0].Hostnames, ",")),
) )
lines := strings.Split(results.Matches[match].Data, "\n") data := strings.Split(results.Matches[match].Data, "\n")
green := true green := true
for line := range lines { for line := range data {
values := strings.Split(lines[line], ":") values := strings.Split(data[line], ":")
if green { if green {
content += fmt.Sprintf("%s:%s\n", utils.Green(values[0]), utils.Blue(strings.Join(values[1:], ""))) if values[0] != ":" {
for value := range values[1:] {
if values[value] != "" {
lines += fmt.Sprintf("%s:%s\n", utils.Green(values[0]), utils.Blue(strings.Join(values[1:], "")))
green = false green = false
break
}
}
}
} else { } else {
content += fmt.Sprintf("%s:%s\n", utils.Blue(values[0]), utils.Green(strings.Join(values[1:], ""))) if values[0] != ":" {
for value := range values[1:] {
if values[value] != "" {
lines += fmt.Sprintf("%s:%s\n", utils.Blue(values[0]), utils.Green(strings.Join(values[1:], "")))
green = true green = true
break
}
}
}
}
}
lines += "\n"
}
} }
} }
s.Results <- content // Remove empty newline
} // Send results
} lines = strings.TrimRight(lines, "\n")
} s.Results <- lines
} }
// Todo: Redo filter sorting // Todo: Redo filter sorting, pages