forked from d3mondev/puredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
49 lines (39 loc) · 1.5 KB
/
runner.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
47
48
49
package massdns
import (
"io"
"os/exec"
"strconv"
)
type defaultRunner struct {
binPath string
execCommand func(name string, arg ...string) *exec.Cmd
}
func newDefaultRunner(binPath string) *defaultRunner {
return &defaultRunner{
binPath: binPath,
execCommand: exec.Command,
}
}
// Run executes massdns on the specified domains files and saves the results to the output file.
func (runner *defaultRunner) Run(r io.Reader, output string, resolvers string, qps int, processes int, socketcount int) error {
// Create massdns program arguments
massdnsArgs := runner.createMassdnsArgs(output, resolvers, qps, processes, socketcount)
// Create a new exec.Cmd and set Stdin and Stdout to our custom handlers to avoid file operations
massdns := runner.execCommand(runner.binPath, massdnsArgs...)
massdns.Stdin = r
// Run massdns and block until it's done
if err := massdns.Run(); err != nil {
return err
}
return nil
}
// createMassdnsArgs creates the command line arguments for massdns.
func (runner *defaultRunner) createMassdnsArgs(output string, resolvers string, qps int, processes int, socketcount int) []string {
// Default command line
args := []string{"-q", "-r", resolvers, "-o", "Snl", "-t", "A", "--root", "--retry", "REFUSED", "--retry", "SERVFAIL", "--processes", processes, "--socket-count", socketcount, "-w", output}
// Set the massdns hashmap size manually to prevent it from accumulating DNS query on start
if qps > 0 {
args = append(args, "-s", strconv.Itoa(qps))
}
return args
}