forked from erbbysam/DNSGrep
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dnsgrep.go
46 lines (37 loc) · 1.07 KB
/
dnsgrep.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// a lightweight utility to scan a sorted file for a substring at the start of each line
package main
import (
. "./DNSBinarySearch"
"fmt"
"os"
"github.com/jessevdk/go-flags"
)
// command line parsing
type Options struct {
Input string `short:"i" long:"input" description:"A hostname to search" required:"true"`
DNSFile string `short:"f" long:"file" description:"A large file containing sorted, reversed domain names" required:"true"`
}
// command line parsing
var options Options
var parser = flags.NewParser(&options, flags.Default)
func main() {
// command line parsing
_, err := parser.Parse()
if err != nil {
panic(err)
}
// increase our limits x10 as we're running this locally
var limits = Limits{
MaxScan: 1000, // 100MB
MaxOutputLines: 1000000, // 1,000,000 lines
}
// main.go is really just a wrapper around this function
output, err := DNSBinarySearch(options.DNSFile, options.Input, limits)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %+v\n", err)
} else {
for _, result := range output {
fmt.Printf("%s\n", result)
}
}
}