-
Notifications
You must be signed in to change notification settings - Fork 4
/
dupknock.py
54 lines (38 loc) · 1.42 KB
/
dupknock.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
import os
import sys
if len(sys.argv)<=1:
print ("""
Dupknock to easily knockout duplicate records from multiple files
python dupknock.py dirname [txt]
""")
exit()
ext = 'txt'
dname = sys.argv[1]
if len(sys.argv) ==3: ext = sys.argv[2]
subdomains=[]
files = []
# List all subdirectories using scandir()
def main(basepath, temp=[], ext='txt'):
exts = ext.split(',')
with os.scandir(basepath) as entries:
for entry in entries:
temppath = basepath
if entry.is_dir():
temppath = temppath+'/'+entry.name
main(temppath, temp)
else:
if entry.name.split('.')[-1] not in exts: continue
temppath = temppath+'/'+entry.name
files.append( ".".join(str(name) for name in entry.name.split('.')[:-1]))
print("[+] Reading "+entry.name)
with open(temppath) as f:
for subdomain in f:
subdomain = subdomain.rstrip("\n")
if subdomain in temp: continue
if len(subdomain) >0:
temp.append(subdomain)
main(dname, subdomains, ext)
print("[-] Writing to final.txt")
with open('{}/{}-finals.txt'.format(dname, "-".join(str(_file) for _file in files)), 'w+') as fh:
for d in subdomains:
fh.write(d+"\n")