Skip to content

Commit da722db

Browse files
indigo-sadlanddwisiswant0
authored andcommitted
added function that allows to save output into file
1 parent 2441ad7 commit da722db

4 files changed

Lines changed: 46 additions & 7 deletions

File tree

internal/executor/executor.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
package executor
22

33
import (
4+
"bufio"
45
"fmt"
6+
"github.com/projectdiscovery/gologger"
7+
"os"
8+
"sync"
59

610
"github.com/logrusorgru/aurora"
7-
"github.com/projectdiscovery/gologger"
811
"github.com/projectdiscovery/retryabledns"
912
"github.com/pwnesia/dnstake/internal/errors"
1013
"github.com/pwnesia/dnstake/internal/option"
1114
"github.com/pwnesia/dnstake/pkg/dnstake"
1215
"github.com/pwnesia/dnstake/pkg/fingerprint"
1316
)
1417

18+
var mu sync.Mutex
19+
20+
// WriteToFile writes output data into specified file.
21+
func WriteToFile(data, outputFile string) {
22+
23+
mu.Lock()
24+
defer mu.Unlock()
25+
26+
file, err := os.OpenFile(outputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
27+
if err != nil {
28+
gologger.Error().Msg(err.Error())
29+
}
30+
31+
wrt := bufio.NewWriter(file)
32+
33+
_, err = wrt.WriteString(data + "\n")
34+
if err != nil {
35+
gologger.Error().Msg(err.Error())
36+
}
37+
38+
wrt.Flush()
39+
file.Close()
40+
}
41+
1542
// New to execute target hostname
1643
func New(opt *option.Options, hostname string) {
1744
var out = ""
1845

1946
vuln, DNS, err := exec(hostname)
2047
if err != nil {
21-
gologger.Error().Msgf("%s: %s", hostname, err.Error())
48+
out += fmt.Sprintf("[%s] %s: %s", aurora.Red("ERR"), hostname, err.Error())
2249
}
2350

2451
if vuln {
@@ -43,8 +70,14 @@ func New(opt *option.Options, hostname string) {
4370
}
4471
}
4572

46-
fmt.Println(out)
4773
}
74+
75+
if opt.Output != "" {
76+
WriteToFile(out, opt.Output)
77+
}
78+
79+
fmt.Println(out)
80+
4881
}
4982

5083
func exec(hostname string) (bool, fingerprint.DNS, error) {

internal/option/const.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ const (
1818
-t, --target <HOST/FILE> Define single target host/list to check
1919
-c, --concurrent <i> Set the concurrency level (default: 25)
2020
-s, --silent Suppress errors and/or clean output
21+
-o, --output Define path where you want to store the tool's output
2122
-h, --help Display its help`
2223
examples = `
2324
dnstake -t (sub.)domain.tld
2425
dnstake -t hosts.txt
26+
dnstake -t hosts.txt -o ./dnstake.out
2527
cat hosts.txt | dnstake
2628
subfinder -silent -d domain.tld | dnstake
2729
`

internal/option/options.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package option
22

33
// Options define available flag/options
44
type Options struct {
5-
Target string
6-
Concurrency int
7-
Silent bool
8-
List []string
5+
Target string
6+
Concurrency int
7+
Silent bool
8+
List []string
9+
Output string
910
}

internal/option/parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ func Parse() *Options {
2020
flag.BoolVar(&opt.Silent, "s", false, "")
2121
flag.BoolVar(&opt.Silent, "silent", false, "")
2222

23+
flag.StringVar(&opt.Output, "o", "", "")
24+
flag.StringVar(&opt.Output, "output", "", "")
25+
2326
flag.Usage = func() {
2427
showBanner()
2528
h := []string{

0 commit comments

Comments
 (0)