-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilemanager.go
57 lines (53 loc) · 1.21 KB
/
filemanager.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
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strconv"
"time"
)
func readFormattedInput(path string) []Record {
f, err := os.Open(path)
if err != nil {
log.Fatalf("[ERROR] %v", err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
records := make([]Record, 0)
for scanner.Scan() {
records = append(records, Record{
Domain: fmt.Sprintf("%v.", scanner.Text()),
})
}
if err := scanner.Err(); err != nil {
log.Fatalf("[Scanner ERROR] %v", err)
}
return records
}
func writeToDisk(results []Record, dirPath string) {
err := os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
log.Fatalf("[ERROR] %v %v", err, dirPath)
}
filePath := fmt.Sprintf("%v/results-%v.csv", dirPath, time.Now().Unix())
f, _ := os.Create(filePath)
writer := csv.NewWriter(f)
writer.Write([]string{"Domain", "DNSSECExists", "DNSSECValid", "reason", "Algorithms", "Protocols", "KeySizes"})
for _, r := range results {
row := []string{
r.Domain,
strconv.FormatBool(r.DNSSECExists),
strconv.FormatBool(r.DNSSECValid),
r.reason,
r.AlgorithmsUsed,
r.ProtocolsUsed,
r.PublicKeySizes,
}
writer.Write(row)
}
writer.Flush()
f.Close()
fmt.Printf("Successfully wrote output to %v", filePath)
}