-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWhoisSearch.py
87 lines (73 loc) · 2.53 KB
/
WhoisSearch.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
# coding = utf8
___author___ = 'tgllsy'
import argparse
import os
import requests
import json
import csv
import time
key = "" # 请输入你的key
def args():
"""
命令行参数以及说明
"""
parser = argparse.ArgumentParser()
parser.add_argument('-r', '--read', dest='read', help='input whois file path')
parse_args = parser.parse_args()
# 参数为空 输出--help命令
if parse_args.read is None:
parser.print_help()
os._exit(0)
return parse_args.read
def domain(host):
"""
从站长之家api获取到公司数据
"""
url = "http://apidata.chinaz.com/CallAPI/Whois?key=" + key + "&domainName=" + host
print(url)
rqs = requests.get(url)
test = json.loads(rqs.text)
# StateCode = test['StateCode']
# Reason = test['Reason']
# # print(StateCode)
# # print(Reason)
lists = []
if test['Result'] != None:
Result = test['Result']
Host = Result['Host']
ContactPerson = Result['ContactPerson']
Registrar = Result['Registrar']
Email = Result['Email']
Phone = str(Result['Phone'])
CreationDate = str(Result['CreationDate'])
ExpirationDate = str(Result['ExpirationDate'])
WhoisServer = str(Result['WhoisServer'])
DnsServer = str(Result['DnsServer'])
DomainStatus = str(Result['DomainStatus'])
lists = [host, Host, ContactPerson, Registrar, Email, Phone, CreationDate, ExpirationDate, WhoisServer,
DnsServer, DomainStatus]
else:
print(host + " 没有查到备案信息!")
print("当前网站查询到的信息如下:")
print(lists)
return lists
def main():
file_path = args()
time_new = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
outfile = str(time_new) + ".csv"
out = open(outfile, 'w+', encoding='utf-8', newline='')
csv_writer = csv.writer(out)
csv_writer.writerow(['域名', '网站域名', ' 联系人', '注册商', '联系邮箱', ' 联系电话', '创建时间', '过期时间', '域名服务器', 'DNS', '状态'])
try:
with open(file_path, encoding='utf-8') as f:
for line in f.readlines():
lists = domain(line.replace('\n', ''))
print(lists)
csv_writer.writerow(lists)
f.close()
except Exception as e:
print("文件读取出错")
print(e)
out.close()
if __name__ == '__main__':
main()