-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path域名查询.py
52 lines (46 loc) · 2.09 KB
/
域名查询.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
import dns.resolver
def dns_query(domain, dns_server):
resolver = dns.resolver.Resolver()
resolver.nameservers = [dns_server]
while True:
try:
# 发送查询
response_a = resolver.resolve(domain, 'A')
response_aaaa = resolver.resolve(domain, 'AAAA')
response_cname = resolver.resolve(domain, 'CNAME')
# 输出A记录回复
print('A记录查询回复:')
for answer in response_a:
print(f'{domain} 的IPv4地址是:{answer.address}')
print(f"返回数据大小为: {len(response_a.response.to_wire())} bytes")
# 输出AAAA记录回复
print('AAAA记录查询回复:')
for answer in response_aaaa:
print(f'{domain} 的IPv6地址是:{answer.address}')
print(f"返回数据大小为: {len(response_aaaa.response.to_wire())} bytes")
# 输出CNAME记录回复
print('CNAME记录查询回复:')
for answer in response_cname:
print(f'{domain} 的CNAME记录是:{answer.target}')
print(f"返回数据大小为: {len(response_cname.response.to_wire())} bytes")
break
except dns.exception.DNSException as e:
print(f'DNS查询失败:{e}')
print(f"请跟换域名{e}或DNS再次进行查询")
break
print("域名查询-Python(3.11.4)\n作者:wangshijiang\n"
"GitHub: https://github.com/iwqculrbud/wangshijiang-python.git\n"
"QQ: 3145865693")
while True:
dns_query(domain=input("输入查询的域名(建议为xx.com格式): "),
dns_server=input("输入DNS服务器(建议为114.114.114.114):"
))
while True:
decide = input("您还要继续吗?(y/n): ")
if decide.lower() == 'n':
exit(1)
elif decide.lower() == 'y':
print("谢谢您的支持!!!")
break
else:
print(f"您输入的 {decide} 不合规,只有y/n(不分大小写)。")