-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdomain.py
More file actions
49 lines (39 loc) · 1.03 KB
/
domain.py
File metadata and controls
49 lines (39 loc) · 1.03 KB
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
#!/usr/bin/env python3
import os
import sys
import tldextract
#Check command line for inputs
if len(sys.argv) < 3:
print("Wrong parameter")
print("python3 domain.py input_file output_file")
sys.exit(1)
#Reading command line arguments
subdom = (sys.argv[1])
sort = (sys.argv[2])
raw = "raw_domain.txt"
with open(subdom) as o:
if os.path.exists("raw_domain.txt"):
print(">>Removing existing Raw Domain file!")
os.remove(raw)
print(">>Creating new Raw Domain file!")
with open (raw,"w") as r:
for url in o:
ext = tldextract.extract(url)
domain = ext.registered_domain
r.write(domain)
r.write('\n')
else:
with open (raw,"w") as r:
for url in o:
ext = tldextract.extract(url)
domain = ext.registered_domain
r.write(domain)
r.write('\n')
with open(raw,"r") as rr:
rr = [item.lower().replace("\n", "") for item in rr.readlines()]
with open(sort, "w") as s:
for item in sorted(set(rr)):
s.write(item.lower()+"\n")
print(">>Removing Raw Domains file")
os.remove(raw)
print ("Task completed!")