-
Notifications
You must be signed in to change notification settings - Fork 1
/
cname_finder.py
88 lines (70 loc) · 1.76 KB
/
cname_finder.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import sys
import queue
import threading
import re
import dns.resolver
from dns.rcode import to_text
from dns.exception import DNSException
from colorama import Fore, init
#enable coloring on win
try:
import win_unicode_console
win_unicode_console.enable()
init()
except ImportError:
pass
#queue and lock var
domains = queue.Queue()
lock = threading.Lock()
# reading args
try:
sublist = sys.argv[1]
except IndexError:
sublist = ""
# reading file
try:
subfile = open(sublist, 'r')
except IOError:
subfile = sublist.split(",")
# setting dns resolver
my_resolver = dns.resolver.Resolver()
my_resolver.nameservers = ['8.8.8.8']
# populate queue with domains
for sub in subfile:
domains.put(sub.strip())
try:
subfile.close()
except AttributeError:
pass
#Example: cname.skype.txt
file_name = "cname."+str(sys.argv[1])
F = open(file_name,"a")
# checking cname
def Check(domain):
try:
answer = my_resolver.query(domain, 'CNAME')
list_cnam =[]
for data in answer:
with lock:
cname_string = str(data.target).rstrip(".")
#cname_error = to_text(answer.response.rcode()).lower()
print("{0:30}{1} -->\t {2}{3}".format(domain, Fore.LIGHTBLUE_EX, Fore.RESET, cname_string))
x = re.search("[.]trafficmanager[.]net$",cname_string)
if x:
list_cnam.append(cname_string[0:-19])
F.writelines("%s\n" %i for i in list_cnam)
except DNSException:
pass
domains.task_done()
# starting threads
while not domains.empty():
domain = domains.get()
try:
threading.Thread(target=Check,args=(domain,)).start()
# avoid thread start error
except RuntimeError:
domains.task_done()
domains.put(domain)
# wait until all threads done
domains.join()
F.close()