diff --git a/Client.go b/Client.go index 1f35cfd..4901e31 100644 --- a/Client.go +++ b/Client.go @@ -55,7 +55,6 @@ func (sc *SearchResultsClient) SearchResult() *SearchResult { func GetSearchResults(scope string, query string, page int) ([]*SearchResult, error) { url := fmt.Sprintf( "https://leakix.net/search?scope=%s&q=%s&page=%d", url2.QueryEscape(scope), url2.QueryEscape(query), page) - log.Println(url) var searchResults []*SearchResult req, _ := http.NewRequest("GET", url, nil) req.Header.Set("Accept", "application/json") diff --git a/cmd/leakix/main.go b/cmd/leakix/main.go new file mode 100644 index 0000000..38aae9c --- /dev/null +++ b/cmd/leakix/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "flag" + "fmt" + "gitlab.nobody.run/tbi/LeakIXClient" + "html/template" + "log" + "os" +) + +func main() { + var scope string + flag.StringVar(&scope, "s", "leak", "Specify scope, default to leak") + var query string + flag.StringVar(&query, "q", "*", "Specify search query, default to *") + var outputTemplate string + flag.StringVar(&outputTemplate, "t", "{{ .Ip }}:{{ .Port }}", "Specify output template, default to \"{{ .Ip }}:{{ .Port }}\"") + var limit int + flag.IntVar(&limit, "l", 100, "Limit results output, default to 100") + + flag.Usage = func() { + fmt.Printf("Usage of leakix: \n") + fmt.Printf(" ./leakix -q '*' -l 200\n\n") + flag.PrintDefaults() + } + + flag.Parse() + + searcher := LeakIXClient.SearchResultsClient{ + Scope: scope, + Query: query, + } + + tmpl, err := template.New("output").Parse(outputTemplate + "\n") + if err != nil { + log.Println("Template error :") + log.Fatal(err) + } + count := 0 + for searcher.Next() { + count++ + err = tmpl.Execute(os.Stdout, searcher.SearchResult()) + if err != nil { + log.Println("Template error :") + log.Fatal(err) + } + if count >= limit { + os.Exit(0) + } + } +}