11package executor
22
33import (
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
1643func 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
5083func exec (hostname string ) (bool , fingerprint.DNS , error ) {
0 commit comments