-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusage.py
More file actions
68 lines (53 loc) · 2.27 KB
/
Copy pathusage.py
File metadata and controls
68 lines (53 loc) · 2.27 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from dns_observe import DNSQuery, RecordType, ResponseList
def print_answers(responses: ResponseList):
for res in responses:
print(f'{res}')
print(f'┌ Answer: {res.answer_n} RRs')
for ans in res.answer_RRs:
print(f'└ {ans}')
print(f'┌ Authority: {res.authority_n} RRs')
for aut in res.authority_RRs:
print(f'└ {aut}')
print(f'┌ Additional: {res.additional_n} RRs')
for adi in res.additional_RRs:
print(f'└ {adi}')
print('---\n')
# custom transaction ID for dns query, useful for tracking specific queries in logs or network captures
dns = DNSQuery('1.1.1.1', wait_time=3, transaction_id=53)
responses: ResponseList = dns.query("api.openai.com")
print_answers(responses)
# query with type AAAA (IPv6 address)
responses = dns.query('api.openai.com', RecordType.AAAA)
print('🤥 fake responses:')
print_answers(responses.fakes()) # 打印伪造的响应列表
print('👌 real response:')
print(responses.real()) # 打印真实的响应
print('---\n')
with DNSQuery('8.8.8.8', wait_time=3) as dns2:
responses = dns2.query('www.google.com', RecordType.A)
print_answers(responses)
# query with type CNAME (canonical name record)
responses = dns2.query('www.twitter.com', RecordType.CNAME)
print_answers(responses)
# query with type TXT (text record)
responses = dns2.query('example.com', RecordType.TXT)
print_answers(responses)
# query with type HTTPS (HTTPSSVC record, RFC 7553)
responses = dns2.query('example.com', RecordType.HTTPS)
print_answers(responses)
# query with type NS (name server record)
responses = dns2.query('example.com', RecordType.NS)
print_answers(responses)
# query with type MX (mail exchange record)
responses = dns2.query('mails.dev', RecordType.MX)
print_answers(responses)
for msg in dns2.stdout_msg:
print(f'{msg}')
with DNSQuery('a.gtld-servers.net', wait_time=3) as dns3:
responses = dns3.query('example.com', RecordType.A)
print_answers(responses)
for msg in dns3.stdout_msg:
print(f'{msg}')
with DNSQuery('8.8.8.8', wait_time=3) as dns4:
responses = dns4.query('googleapis.com', RecordType.HTTPS)
print_answers(responses)