forked from macvk/dnsleaktest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsleaktest.go
More file actions
131 lines (103 loc) · 2.17 KB
/
Copy pathdnsleaktest.go
File metadata and controls
131 lines (103 loc) · 2.17 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"sync"
"time"
)
var ApiDomain = "bash.ws"
type Block struct {
Ip string `json:"ip"`
Country string `json:"country"`
CountryName string `json:"country_name"`
Asn string `json:"asn"`
Type string `json:"type"`
}
func _pError(err error) {
if err != nil {
panic(err)
}
}
func _random(min, max int) int {
rand.Seed(time.Now().Unix())
return rand.Intn(max-min) + min
}
func fakePing() int {
var wg sync.WaitGroup
rSubDomainId1 := _random(1000000, 9999999)
for i := 0; i <= 10; i++ {
initUrl := fmt.Sprintf("https://%d.%d.%s", i, rSubDomainId1, ApiDomain)
wg.Add(1)
go func(initUrl string) {
defer wg.Done()
http.Get(initUrl)
}(initUrl)
}
wg.Wait()
return rSubDomainId1
}
func getResult(id int) []Block {
getUrl := fmt.Sprintf("https://%s/dnsleak/test/%d?json", ApiDomain, id)
// send GET request
res, err := http.Get(getUrl)
_pError(err)
defer res.Body.Close()
var data []Block
if res.StatusCode == http.StatusOK {
bodyBytes, _ := ioutil.ReadAll(res.Body)
err = json.Unmarshal(bodyBytes, &data)
if err != nil {
fmt.Println(err)
}
}
return data
}
func printResult(result []Block, Type string) {
for _, Block := range result {
if Block.Type != Type {
continue
}
if Block.Asn != "" {
fmt.Printf("%s [%s, %s]\n", Block.Ip, Block.CountryName, Block.Asn)
continue
}
if Block.CountryName != "" {
fmt.Printf("%s [%s]\n", Block.Ip, Block.CountryName)
continue
}
if Block.Ip != "" {
fmt.Printf("%s\n", Block.Ip)
}
}
}
func main() {
//create new request to server to get an id fo testing
testId := fakePing()
//test DNS leak
result := getResult(testId)
//show the testing result
dns := 0
for _, Block := range result {
switch Block.Type {
case "dns":
dns++
}
}
fmt.Print("Your IP:\n")
printResult(result, "ip")
if dns == 0 {
fmt.Print("No DNS servers found\n")
} else {
if dns == 1 {
fmt.Printf("You use %d DNS server:\n", dns)
} else {
fmt.Printf("You use %d DNS servers:\n", dns)
}
printResult(result, "dns")
}
fmt.Print("Conclusion:\n")
printResult(result, "conclusion")
}