-
Notifications
You must be signed in to change notification settings - Fork 0
/
masswhois.py
executable file
·60 lines (45 loc) · 1.38 KB
/
masswhois.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
#!/usr/bin/python
import pythonwhois;
import argparse;
import sys;
def pick_name(whois_info):
try:
return whois_info['contacts']['admin']['name'];
except:
try:
return whois_info['contacts']['registrant']['name'];
except:
return "unknown";
def pick_registrar(whois_info):
try:
return whois_info['registrar'][0];
except:
return "unknown";
def lookup_domain_list(domain_list):
whois_results=[];
for dns_name in domain_list:
try:
dns_name = dns_name.strip();
if len(dns_name)>0:
print("Looking up:\"" + dns_name + "\"");
whois_info = pythonwhois.get_whois(dns_name);
assoc_name=pick_name(whois_info).replace(',','.');
registrar=pick_registrar(whois_info).replace(',','.');
whois_results.append([dns_name, registrar, assoc_name,whois_info['updated_date'][0].isoformat(' ')]);
except:
print("Error looking up:" +dns_name);
for dns_list in whois_results:
sys.stdout.write("%s\n" %(",".join(map(str,dns_list))))
def main(argv):
parser = argparse.ArgumentParser();
parser.add_argument('-i', '--infile', default='');
args = parser.parse_args();
domain_list='';
if vars(args)['infile'] == '':
domain_list=sys.stdin;
else:
f=open(vars(args)['infile']);
domain_list=f.readlines();
lookup_domain_list(domain_list);
if __name__ == "__main__":
main(sys.argv[1:]);