Skip to content

Commit 0189d62

Browse files
committed
Added output directory flag
1 parent 071c01c commit 0189d62

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ Program will resolve each domain and report execution time statistics.
1111
### usage
1212

1313
```
14-
Usage: ./main [options] -ns {nameserver}
14+
Usage: ./dns-subnet-client [options] -ns {nameserver}
1515
1616
-client string
1717
set edns client-subnet option
1818
-d string
1919
dns query wordlists file
2020
-ns string
2121
set preferred nameserver (default "8.8.8.8")
22+
-o string
23+
output directory for data graph (default "data")
2224
-t int
2325
number of threads (default 100)
2426
-v enable verbose output of dns queries (debug)

graph/graph.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
)
1111

1212
// BuildGraph initializes new 2-axis graph
13-
func BuildGraph(nameserver string, clientStatus bool, t, c []float64, threads, dmnCount int) {
13+
func BuildGraph(nameserver string, clientStatus bool, t, c []float64,
14+
threads, dmnCount int, output string) {
1415
mainSeries := chart.ContinuousSeries{
1516
Name: "Rate",
1617
XValues: t,
@@ -25,7 +26,7 @@ func BuildGraph(nameserver string, clientStatus bool, t, c []float64, threads, d
2526
} // we can optionally set the `WindowSize` property which alters how the moving average is calculated.
2627

2728
graph := chart.Chart{
28-
Title: fmt.Sprintf("%v - [subnet_client: %v, thread_count:%v, domain_list:%v",
29+
Title: fmt.Sprintf("%v - +subnet_client: %v, +thread_count:%v, +domain_list:%v",
2930
nameserver, clientStatus, threads, dmnCount),
3031
TitleStyle: chart.Style{
3132
FontSize: 12.0,
@@ -75,9 +76,12 @@ func BuildGraph(nameserver string, clientStatus bool, t, c []float64, threads, d
7576
chart.Legend(&graph),
7677
}
7778

78-
outputDir := "data"
79+
if _, err := os.Stat(output); os.IsNotExist(err) {
80+
os.Mkdir(output, os.ModePerm)
81+
}
82+
7983
f, err := os.Create(fmt.Sprintf("%v/ns-%v_client-%v_%4v.png",
80-
outputDir, nameserver, clientStatus, time.Now().Unix()))
84+
output, nameserver, clientStatus, time.Now().Unix()))
8185
if err != nil {
8286
log.Printf("Error writing to file\n%v", err)
8387
}

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var (
1919
nameserver = flag.String("ns", "8.8.8.8", "set preferred nameserver")
2020
threads = flag.Int("t", 100, "number of threads")
2121
verbose = flag.Bool("v", false, "enable verbose output of dns queries (debug)")
22+
output = flag.String("o", "data", "output directory for data graph")
2223
)
2324

2425
type statistics struct {
@@ -125,10 +126,13 @@ func updateStats(done chan bool) {
125126

126127
func finalStats() {
127128
graph.BuildGraph(*nameserver, len(*client) != 0, timeValues,
128-
rateValues, *threads, domainCount)
129+
rateValues, *threads, domainCount, *output)
129130

130-
fmt.Printf("\n\nFinal Statistics\nAttempts: %v\nSuccess: %v\nFailed: %v\n\n"+
131-
"Avg Rate: %v queries/sec",
131+
fmt.Printf("\n\nFinal Statistics\n"+
132+
"Attempts: %v\n"+
133+
"Success: %v\n"+
134+
"Failed: %v\n\n"+
135+
"Avg Rate: %v queries/s",
132136
Stats.attempts, Stats.success, Stats.fail, getStatAvg())
133137
}
134138

0 commit comments

Comments
 (0)