From 38dac8cbe42c0aaed826dd2540174c3402ca3f09 Mon Sep 17 00:00:00 2001 From: Gregory Boddin Date: Sun, 26 Jul 2020 17:48:19 +0200 Subject: [PATCH] Added client, removed debug from library --- Client.go | 1 - cmd/leakix/main.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 cmd/leakix/main.go 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) + } + } +}