forked from macvk/dnsleaktest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsleaktest.py
executable file
·72 lines (61 loc) · 2.08 KB
/
dnsleaktest.py
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
#!/usr/bin/env python3
# encoding=utf-8
# Any questions: tutumbul@gmail.com
# https://bash.ws/dnsleak
import os
import subprocess
import json
from random import randint
from platform import system as system_name
from subprocess import call as system_call
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
def ping(host):
fn = open(os.devnull, 'w')
param = '-n' if system_name().lower() == 'windows' else '-c'
command = ['ping', param, '1', host]
retcode = system_call(command, stdout=fn, stderr=subprocess.STDOUT)
fn.close()
return retcode == 0
leak_id = randint(1000000, 9999999)
for x in range(0, 10):
ping('.'.join([str(x), str(leak_id), "bash.ws"]))
response = urlopen("https://bash.ws/dnsleak/test/"+str(leak_id)+"?json")
data = response.read().decode("utf-8")
parsed_data = json.loads(data)
print("Your IP:")
for dns_server in parsed_data:
if dns_server['type'] == "ip":
if dns_server['country_name']:
if dns_server['asn']:
print(dns_server['ip']+" ["+dns_server['country_name']+", " +
dns_server['asn']+"]")
else:
print(dns_server['ip']+" ["+dns_server['country_name']+"]")
else:
print(dns_server['ip'])
servers = 0
for dns_server in parsed_data:
if dns_server['type'] == "dns":
servers = servers + 1
if servers == 0:
print("No DNS servers found")
else:
print("You use "+str(servers)+" DNS servers:")
for dns_server in parsed_data:
if dns_server['type'] == "dns":
if dns_server['country_name']:
if dns_server['asn']:
print(dns_server['ip']+" ["+dns_server['country_name'] +
", " + dns_server['asn']+"]")
else:
print(dns_server['ip']+" ["+dns_server['country_name']+"]")
else:
print(dns_server['ip'])
print("Conclusion:")
for dns_server in parsed_data:
if dns_server['type'] == "conclusion":
if dns_server['ip']:
print(dns_server['ip'])