Skip to content

Commit

Permalink
Added client, removed debug from library
Browse files Browse the repository at this point in the history
  • Loading branch information
gboddin committed Jul 26, 2020
1 parent ccfc0cc commit 38dac8c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
1 change: 0 additions & 1 deletion Client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
52 changes: 52 additions & 0 deletions cmd/leakix/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 38dac8c

Please sign in to comment.