-
Notifications
You must be signed in to change notification settings - Fork 1
/
whois_main.py
60 lines (45 loc) · 1.5 KB
/
whois_main.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
import subprocess
import re
import tldextract
from data_if_loop import domain_lookup
with open("domain_list.txt") as f:
domain_all = f.read().splitlines()
with open ("domain_out.txt", "w") as f:
f.write("")
temp = []
for domain in domain_all:
domain = tldextract.extract(domain)
domain = "{}.{}".format(domain.domain, domain.suffix)
domain_all = set(domain)
if domain not in temp:
temp.append(domain)
try:
temp.remove('.')
except:
pass
for domain in temp:
print (domain)
tld = domain_lookup(domain)
def whois(ip,name):
p = subprocess.Popen(['whois', ip], stdout=subprocess.PIPE)
out, err = p.communicate()
m = re.search(tld.get(name), out.decode('ISO-8859-9'))
return m.group(1)
def whois_server(ip,name):
p = subprocess.Popen(['whois', ip], stdout=subprocess.PIPE)
out, err = p.communicate()
try:
m = re.findall(tld.get(name), out.decode('ISO-8859-9'))
except:
m = re.findall(tld.get(name), out.decode('ISO-8859-9')).group(1)
return m
with open("domain_out.txt", "a") as f:
f.writelines(domain)
f.writelines("\n")
try:
f.writelines(" " + whois(domain, "expiration_date") + "\n")
f.writelines(" " + str(whois_server(domain, "name_servers")) + "\n")
f.writelines(" " + whois(domain, "status") + "\n")
except:
f.writelines("\n")
f.writelines("\n")