From 11ac7082303740beda951d4fc22e1786e8e32dea Mon Sep 17 00:00:00 2001 From: Mohamed Salah Date: Sun, 28 Oct 2018 01:32:39 +0200 Subject: [PATCH] golang version --- README.md | 64 ++++++++++++++++++++++++++++++++++++- dnsleaktest.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 dnsleaktest.go diff --git a/README.md b/README.md index ad6e15c..1b15af1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Dns Leak Test The test shows DNS leaks and your external IP. If you use the same ASN for DNS and connection - you have no leak, otherwise here might be a problem. -## How to install & use +## How to install & use Python Version ### Linux @@ -47,4 +47,66 @@ chmod +x dnsleaktest.py 2. Run dnsleaktest.py ``` ./dnsleaktest.py +``` + + +----------------------------------------------------- + +## How to build & use Golang Version + +1. Download executable binary for Linux, MacOs or Windows without build: + +### Linux + +1. Download [dnsleaktest](https://www.dropbox.com/s/aarf10zls3xvu6z/dnsleaktest?dl=0) + +``` +chmod +x dnsleaktest +``` + +2. Run dnsleaktest +``` +./dnsleaktest +``` + +### Windows + +1. Download [dnsleaktest.exe](https://www.dropbox.com/s/ubee3tp3c41owcj/dnsleaktest.exe?dl=0) + +2. Run dnsleaktest.exe, +open cmd then navigate to the exe file +``` +dnsleaktest.exe +``` + +### macOS + +1. Download [dnsleaktest](https://www.dropbox.com/s/aarf10zls3xvu6z/dnsleaktest?dl=0) + +``` +chmod +x dnsleaktest +``` + +2. Run dnsleaktest +``` +./dnsleaktest +``` + +### Or build binaries in your machine + +1. Linux +``` +GOOS=linux GOARCH=386 go build -o dnsleaktest dnsleaktest.go + +``` +2. MacOS + +``` +GOOS=linux GOARCH=386 go build -o dnsleaktest dnsleaktest.go +``` +3. Windows + +``` +GOOS=windows GOARCH=386 go build -o dnsleaktest.exe dnsleaktest.go + ``` \ No newline at end of file diff --git a/dnsleaktest.go b/dnsleaktest.go new file mode 100644 index 0000000..3711d11 --- /dev/null +++ b/dnsleaktest.go @@ -0,0 +1,85 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "math/rand" + "net/http" + "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 { + + rSubDomainId1 := _random(1000000, 9999999) + rSubDomainId2 := _random(1, 10) + initUrl := fmt.Sprintf("https://%d.%d.%s", rSubDomainId2, rSubDomainId1, ApiDomain) + http.Get(initUrl) + return rSubDomainId1 + +} + +func getResult(id int) []Block { + + getUrl := fmt.Sprintf("https://%s/dnsleak/test/%d?json", ApiDomain, id) + // create post 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 main() { + //create new request to server to get an id fo testing + testId := fakePing() + //test DNS leak + result := getResult(testId) + //show the testing result + for _, Block := range result { + switch Block.Type { + + case "ip": + fmt.Printf("Your IP: \n%s [%s, %s]\n", Block.Ip, Block.CountryName, Block.Asn) + case "dns": + fmt.Printf("DNS Server: %s [%s, %s]\n", Block.Ip, Block.CountryName, Block.Asn) + case "conclusion": + defer fmt.Printf("Conclusion: \n%s\n", Block.Ip) + } + + } +}