Skip to content

Commit

Permalink
Updated: "DoH Method, makefile"
Browse files Browse the repository at this point in the history
Added: "Latency and Timeout"
  • Loading branch information
cody0704 committed Mar 29, 2022
1 parent 0416e56 commit fbdc74e
Show file tree
Hide file tree
Showing 20 changed files with 424 additions and 192 deletions.
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)

compile:
echo "Compiling for every OS and Platform"
GOOS=freebsd GOARCH=amd64 go build -o ./bin/$(NAME)_$(VERSION)_freebsd-amd64 -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
GOOS=linux GOARCH=amd64 go build -o ./bin/$(NAME)_$(VERSION)_linux-amd64 -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
GOOS=darwin GOARCH=amd64 go build -o ./bin/$(NAME)_$(VERSION)_darwin-amd64 -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
GOOS=windows GOARCH=amd64 go build -o ./bin/$(NAME)_$(VERSION)_windows-amd64 -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
GOOS=freebsd GOARCH=amd64 go build -o ./bin/$(NAME) -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
zip ./bin/$(NAME)_$(VERSION)_freebsd-amd64.zip ./bin/$(NAME)
rm -rf ./bin/$(NAME)

GOOS=linux GOARCH=amd64 go build -o ./bin/$(NAME) -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
zip ./bin/$(NAME)_$(VERSION)_linux-amd64.zip ./bin/$(NAME)
rm -rf ./bin/$(NAME)

GOOS=darwin GOARCH=amd64 go build -o ./bin/$(NAME) -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
zip ./bin/$(NAME)_$(VERSION)_darwin-amd64.zip ./bin/$(NAME)
rm -rf ./bin/$(NAME)

GOOS=windows GOARCH=amd64 go build -o ./bin/$(NAME).exe -ldflags '-X "main.versionID=$(VERSION)"' ./cmd/dotbomb
zip ./bin/$(NAME)_$(VERSION)_windows-amd64.zip ./bin/$(NAME).exe
rm -rf ./bin/$(NAME).exe
127 changes: 90 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Support DNS and DoH by the way

```
-v show version
-m mode: dns / dot / doh
-m mode: dns / dot / doh / dohg / dohp
-c number of concurrency
-t last Recv Packet Timeout
-t Timeout
-l Latency interval
-n number of query
-r DNS Over TLS Server IP
-p Port, default is 853
Expand All @@ -21,64 +22,116 @@ Support DNS and DoH by the way
* DoT

```bash
$ dotbomb -m dot -c 20 -n 100 -r 8.8.8.8 -f domains.txt
2022/03/26 15:44:10 DoTBomb start stress...
2022/03/26 15:44:10 Mode: dot
2022/03/26 15:44:10 DNS Over TLS Server: 8.8.8.8:853
Progress: 2000/2000
$ dotbomb -m dot -c 6 -n 120 -t 3 -l 6000 -r 8.8.8.8 -f domains.txt
2022/03/29 14:48:39 DoTBomb start stress...
2022/03/29 14:48:39 Timeout: 3s
2022/03/29 14:48:39 Latency: 0.006s
2022/03/29 14:48:39 Mode: dot
2022/03/29 14:48:39 DoT Server: 8.8.8.8:853
Progress: 120/120

Status: Finish
Finish Time: 2.172188s
Avg Latency: 0.001086s
Time: 0.436902s
Avg Latency: 0.003641s
==========================================
Send: 2000
Recv: 2000
Answer: 1980
NoAnswer: 20
Timeout: 0
Other: 0
Send: 120
Recv: 120
Answer: 120
NoAnswer: 0
Timeout: 0
Other: 0
```

* DNS

```bash
$ dotbomb -m dns -c 20 -n 50 -r 8.8.8.8 -f domains.txt
2022/03/26 15:44:44 DoTBomb start stress...
2022/03/26 15:44:44 Mode: dns
2022/03/26 15:44:44 DNS Server: 8.8.8.8:53
Progress: 1000/1000
$ dotbomb -m dns -c 4 -n 25 -t 2 -l 3000 -r 8.8.8.8 -f domains.txt
2022/03/29 14:49:31 DoTBomb start stress...
2022/03/29 14:49:31 Timeout: 2s
2022/03/29 14:49:31 Latency: 0.003s
2022/03/29 14:49:31 Mode: dns
2022/03/29 14:49:31 DNS Server: 8.8.8.8:53
Progress: 100/100

Status: Finish
Finish Time: 1.569659s
Avg Latency: 0.001571s
Time: 0.530679s
Avg Latency: 0.005307s
==========================================
Send: 1000
Recv: 1000
Answer: 999
Send: 100
Recv: 100
Answer: 100
NoAnswer: 0
Timeout: 1
Timeout: 0
Other: 0
```

* DoH

* Default

```bash
$ dotbomb -m doh -c 6 -n 10 -t 5 -l 1000 -r 8.8.8.8 -f domains.txt
2022/03/29 14:50:09 DoTBomb start stress...
2022/03/29 14:50:09 Timeout: 5s
2022/03/29 14:50:09 Latency: 0.001s
2022/03/29 14:50:09 Mode: doh Method: POST
2022/03/29 15:30:26 DoH Server: https://8.8.8.8:443/dns-query{?dns}
Progress: 60/60

Status: Finish
Time: 0.192230s
Avg Latency: 0.003204s
==========================================
Send: 60
Recv: 60
Answer: 60
NoAnswer: 0
Timeout: 0
Other: 0
```

* POST

```bash
$ dotbomb -m doh -c 20 -n 300 -r 8.8.8.8 -f domains.txt
2022/03/26 15:45:10 DoTBomb start stress...
2022/03/26 15:45:10 Mode: doh
2022/03/26 15:45:10 DNS Over HTTPS Server: https://8.8.8.8:443/dns-query
Progress: 6000/6000
$ dotbomb -m dohp -c 5 -n 14 -t 3 -l 6000 -r 8.8.8.8 -f domains.txt
2022/03/29 14:50:46 DoTBomb start stress...
2022/03/29 14:50:46 Timeout: 3s
2022/03/29 14:50:46 Latency: 0.006s
2022/03/29 14:50:46 Mode: dohp Method: POST
2022/03/29 15:30:26 DoH Server: https://8.8.8.8:443/dns-query{?dns}
Progress: 70/70

Status: Finish
Finish Time: 18.190158s
Avg Latency: 0.003032s
Time: 0.460050s
Avg Latency: 0.006572s
==========================================
Send: 6000
Recv: 6000
Answer: 5820
NoAnswer: 180
Send: 70
Recv: 70
Answer: 70
NoAnswer: 0
Timeout: 0
Other: 0
```

* GET

```bash
$ dotbomb -m dohg -c 100 -n 5 -t 10 -l 6500 -r 8.8.8.8 -f domains.txt
2022/03/29 15:30:26 DoTBomb start stress...
2022/03/29 15:30:26 Timeout: 10s
2022/03/29 15:30:26 Latency: 0.0065s
2022/03/29 15:30:26 Mode: dohg Method: GET
2022/03/29 15:30:26 DoH Server: https://8.8.8.8:443/dns-query{?dns}
Progress: 500/500

Status: Finish
Time: 0.649415s
Avg Latency: 0.001299s
==========================================
Send: 500
Recv: 500
Answer: 500
NoAnswer: 0
Timeout: 0
Other: 0
```
15 changes: 11 additions & 4 deletions cmd/dotbomb/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ var (
timeout int
concurrency int
totalRequest int
latency int
requestIP string
requestPort string
domainFile string
)

func init() {
flag.BoolVar(&version, "v", false, "number of concurrency")
flag.StringVar(&mode, "m", "dot", "dot / doh / dns")
flag.IntVar(&timeout, "t", 3, "Last Recv Packet Timeout")
flag.StringVar(&mode, "m", "dot", "dot / doh Method: Post / dohp: DoH Method - Post / doh: DoH Method - Get / dns")
flag.IntVar(&latency, "l", 0, "request latency")
flag.IntVar(&timeout, "t", 1, "request Timeout")
flag.IntVar(&concurrency, "c", 1, "number of concurrency")
flag.IntVar(&totalRequest, "n", 1, "number of request")
flag.StringVar(&requestIP, "r", "", "request ip address")
Expand All @@ -38,7 +40,8 @@ func init() {
if concurrency == 0 || totalRequest == 0 || requestIP == "" || mode == "" {
fmt.Println("Example: dotbomb -m dot -c 10 -n 100 -r 8.8.8.8 -p 853 -f domains.txt")
fmt.Println("-v [Version]")
fmt.Println("-m [Mode] Default: dot, Option: dot / doh / dns")
fmt.Println("-m [Mode] Default: dot, Option: dot / doh (doh - POST, dohg - GET, dohp - POST) / dns")
fmt.Println("-l [Request Latency] <Number> Microsecond Unit 0.000001")
fmt.Println("-c [Concurrency] <Number>")
fmt.Println("-t [Timeout] <Second>")
fmt.Println("-n [request] <Number>")
Expand All @@ -50,7 +53,7 @@ func init() {
}

switch mode {
case "dns", "dot", "doh":
case "dns", "dot", "doh", "dohg", "dohp":
default:
fmt.Println("-m [Mode] Default: dot, Option: dot / doh / dns")
os.Exit(0)
Expand All @@ -64,6 +67,10 @@ func init() {
requestPort = "853"
case "doh":
requestPort = "443"
case "dohg":
requestPort = "443"
case "dohp":
requestPort = "443"
}
}
}
74 changes: 62 additions & 12 deletions cmd/dotbomb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
"syscall"
"time"

"github.com/cody0704/dotbomb/server"
"github.com/cody0704/dotbomb/pkg/stress"
)

func main() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

var bomb = server.Bomb{
var bomb = stress.Bomb{
Concurrency: concurrency,
TotalRequest: totalRequest,
RequestIP: requestIP,
RequestPort: requestPort,
LastTimeout: time.Second * time.Duration(timeout),
Server: requestIP + ":" + requestPort,
Timeout: time.Second * time.Duration(timeout),
Latency: time.Microsecond * time.Duration(latency),
}

file, err := os.Open(domainFile)
Expand All @@ -49,33 +49,84 @@ func main() {
file.Close()

log.Println("DoTBomb start stress...")
log.Println("Mode:", mode)
log.Printf("Timeout: %ds", timeout)
log.Printf("Latency: %.6gs", bomb.Latency.Seconds())

switch mode {
case "dns":
log.Println("Mode:", mode)
if !bomb.VerifyDNS() {
log.Println("Cannot connect to DNS Server:", bomb.Server)
os.Exit(0)
return
}
log.Println("DNS Server:", bomb.Server)

go bomb.DNS()
case "dot":
log.Println("Mode:", mode)
if !bomb.VerifyDoT() {
log.Println("Cannot connect to DoT Server:", bomb.Server)
os.Exit(0)
return
}
log.Println("DoT Server:", bomb.Server)

go bomb.DoT()
case "doh":
log.Println("Mode:", mode, "Method: POST")
bomb.Server = "https://" + bomb.Server + "/dns-query{?dns}"
bomb.Method = "POST"
if !bomb.VerifyDoH() {
log.Println("Cannot connect to DoH Server:", bomb.Server)
os.Exit(0)
return
}
log.Println("DoH Server:", bomb.Server)

go bomb.DoH()
case "dohp":
log.Println("Mode:", mode, "Method: POST")
bomb.Server = "https://" + bomb.Server + "/dns-query{?dns}"
bomb.Method = "POST"
if !bomb.VerifyDoH() {
log.Println("Cannot connect to DoH Server:", bomb.Server)
os.Exit(0)
return
}
log.Println("DoH Server:", bomb.Server)

go bomb.DoH()
case "dohg":
log.Println("Mode:", mode, "Method: GET")
bomb.Server = "https://" + bomb.Server + "/dns-query{?dns}"
bomb.Method = "GET"
if !bomb.VerifyDoH() {
log.Println("Cannot connect to DoH Server:", bomb.Server)
os.Exit(0)
return
}
log.Println("DoH Server:", bomb.Server)

go bomb.DoH()
}

select {
case <-sigChan:
report(server.Result, 1)
case status := <-server.StatusChan:
report(server.Result, status)
report(stress.Result, 1)
case status := <-stress.StatusChan:
report(stress.Result, status)
}
}

func report(report server.StressReport, status int) {
func report(report stress.StressReport, status int) {
switch status {
case 0:
fmt.Println("\n\nStatus:\t\t", "Finish")
case 1:
fmt.Println("\nStatus:\t\t", "Cancle")
}
fmt.Printf("Finish Time:\t %.6fs\n", report.LastTime.Seconds())
fmt.Printf("Time:\t\t %.6fs\n", report.LastTime.Seconds())
totalResponse := report.RecvAnsCount + report.RecvNoAnsCount
avgLantency := report.LastTime.Seconds() / float64(totalResponse)
if math.IsInf(avgLantency, 0) || math.IsNaN(avgLantency) {
Expand All @@ -85,7 +136,6 @@ func report(report server.StressReport, status int) {
}
fmt.Println("==========================================")
fmt.Println("Send:\t\t", report.SendCount)

fmt.Println("Recv:\t\t", report.RecvAnsCount+report.RecvNoAnsCount+report.TimeoutCount+report.OtherCount)
fmt.Println(" Answer:\t", report.RecvAnsCount)
fmt.Println(" NoAnswer:\t", report.RecvNoAnsCount)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.17
require (
github.com/folbricht/routedns v0.1.0
github.com/miekg/dns v1.1.47
github.com/pion/udp v0.1.1
)

replace github.com/folbricht/routedns v0.1.0 => github.com/cody0704/routedns v0.2.0
replace github.com/folbricht/routedns v0.1.0 => github.com/cody0704/routedns v0.2.1

require (
github.com/cheekybits/genny v1.0.0 // indirect
Expand All @@ -25,7 +26,6 @@ require (
github.com/pion/dtls/v2 v2.1.0 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport v0.13.0 // indirect
github.com/pion/udp v0.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cody0704/routedns v0.2.0 h1:J/tXsppijWOX+sk26uVhpbs4M6oin0bUoSNrusuxEfk=
github.com/cody0704/routedns v0.2.0/go.mod h1:Pp+SfnpUj1IjqtdLJ0whmdeW3PCaSSy7ySzqYa0w/Gg=
github.com/cody0704/routedns v0.2.1 h1:pdh125q9b7oT3dnSJg+nA5pCoPAHSyZyFzNGjgtHRV0=
github.com/cody0704/routedns v0.2.1/go.mod h1:Pp+SfnpUj1IjqtdLJ0whmdeW3PCaSSy7ySzqYa0w/Gg=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
Loading

0 comments on commit fbdc74e

Please sign in to comment.