Skip to content

Commit

Permalink
Merge pull request #1 from gitexel/master
Browse files Browse the repository at this point in the history
golang version
  • Loading branch information
macvk authored Oct 28, 2018
2 parents 89e6f18 + 11ac708 commit 6eb5ae6
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 1 deletion.
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
```
85 changes: 85 additions & 0 deletions dnsleaktest.go
Original file line number Diff line number Diff line change
@@ -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)
}

}
}

0 comments on commit 6eb5ae6

Please sign in to comment.