Skip to content

Commit

Permalink
add type AAAA query
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierskip committed Nov 26, 2024
1 parent 5d378f7 commit 1a37c66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/dns_observe/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def query(self, qname, qtype=QueryType.A):
else:
mark = '│'
if answer.type == QueryType.A:
print(f"{mark} Time: {now}, Name: {answer.name}, TTL: {answer.ttl}, A: {answer.ip_address}")
print(f"{mark} Time: {now}, Name: {answer.name}, TTL: {answer.ttl}, A: {answer.ipv4_address}")
elif answer.type == QueryType.AAAA:
print(f"{mark} Time: {now}, Name: {answer.name}, TTL: {answer.ttl}, A: {answer.ipv6_address}")
elif answer.type == QueryType.CNAME:
message = decompression_message(response, answer.data)
print(f"{mark} Time: {now}, Name: {answer.name}, TTL: {answer.ttl}, CNAME: {message}")
Expand Down Expand Up @@ -227,8 +229,12 @@ def __init__(self):
self.data = None

@property
def ip_address(self):
return socket.inet_ntoa(self.data)
def ipv4_address(self):
return socket.inet_ntop(socket.AF_INET, self.data)

@property
def ipv6_address(self):
return socket.inet_ntop(socket.AF_INET6, self.data)

def decompression_message(buff, data):
parts = []
Expand Down
9 changes: 8 additions & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ def test_run(self):
for d in domains:
d = d.strip()
print(f"== {d} ==")
dns = DNSQuery()
dns = DNSQuery(listen_time=1, timeout=1)
dns.query(d)

def test_type_AAAA(self):
dns = DNSQuery('223.5.5.5')
domains = ['taobao.com', 'data.bilibili.com', 'www.qq.com']
for d in domains:
print(f"== {d} ==")
dns.query(d)

if __name__ == '__main__':
Expand Down

0 comments on commit 1a37c66

Please sign in to comment.