diff --git a/modules/test/dns/python/src/dns_module.py b/modules/test/dns/python/src/dns_module.py
index c04e289d3..1be69d59a 100644
--- a/modules/test/dns/python/src/dns_module.py
+++ b/modules/test/dns/python/src/dns_module.py
@@ -97,6 +97,7 @@ def generate_module_report(self):
| Source |
Destination |
+ Resolved IP |
Type |
URL |
Count |
@@ -105,16 +106,16 @@ def generate_module_report(self):
'''
# Count unique combinations
- counter = Counter(
- (row['Source'], row['Destination'], row['Type'], row['Data'])
- for row in dns_table_data)
+ counter = Counter((row['Source'], row['Destination'], row['ResolvedIP'],
+ row['Type'], row['Data']) for row in dns_table_data)
# Generate the HTML table with the count column
- for (src, dst, typ, dat), count in counter.items():
+ for (src, dst, res_ip, typ, dat), count in counter.items():
table_content += f'''
| {src} |
{dst} |
+ {res_ip} |
{typ} |
{dat} |
{count} |
@@ -166,23 +167,38 @@ def extract_dns_data(self):
# 'qr' field indicates query (0) or response (1)
dns_type = 'Query' if dns_layer.qr == 0 else 'Response'
- # Check for the presence of DNS query name
- if hasattr(dns_layer, 'qd') and dns_layer.qd is not None:
+ # Check if 'qd' (query data) exists and has at least one entry
+ if hasattr(dns_layer, 'qd') and dns_layer.qdcount > 0:
qname = dns_layer.qd.qname.decode() if dns_layer.qd.qname else 'N/A'
else:
qname = 'N/A'
+ resolved_ip = 'N/A'
+ # If it's a response packet, extract the resolved IP address
+ # from the answer section
+ if dns_layer.qr == 1 and hasattr(dns_layer,
+ 'an') and dns_layer.ancount > 0:
+ # Loop through all answers in the DNS response
+ for i in range(dns_layer.ancount):
+ answer = dns_layer.an[i]
+ # Check for IPv4 (A record) or IPv6 (AAAA record)
+ if answer.type == 1: # Indicates an A record (IPv4 address)
+ resolved_ip = answer.rdata # Extract IPv4 address
+ break # Stop after finding the first valid resolved IP
+ elif answer.type == 28: # Indicates an AAAA record (IPv6 address)
+ resolved_ip = answer.rdata # Extract IPv6 address
+ break # Stop after finding the first valid resolved IP
+
dns_data.append({
'Timestamp': float(packet.time), # Timestamp of the DNS packet
'Source': source_ip,
'Destination': destination_ip,
+ 'ResolvedIP': resolved_ip, # Adding the resolved IP address
'Type': dns_type,
'Data': qname[:-1]
})
# Filter unique entries based on 'Timestamp'
- # DNS Server will duplicate messages caught by
- # startup and monitor
filtered_unique_dns_data = []
seen_timestamps = set()
diff --git a/testing/unit/dns/reports/dns_report_local.html b/testing/unit/dns/reports/dns_report_local.html
index f62357a95..d107c66b1 100644
--- a/testing/unit/dns/reports/dns_report_local.html
+++ b/testing/unit/dns/reports/dns_report_local.html
@@ -1 +1,98 @@
-DNS Module
| Requests to local DNS server |
Requests to external DNS servers |
Total DNS requests |
Total DNS responses |
| 71 |
0 |
71 |
84 |
| Source |
Destination |
Type |
URL |
Count |
| 10.10.10.14 |
10.10.10.4 |
Query |
mqtt.googleapis.com |
64 |
| 10.10.10.4 |
10.10.10.14 |
Response |
mqtt.googleapis.com |
76 |
| 10.10.10.14 |
10.10.10.4 |
Query |
pool.ntp.org |
7 |
| 10.10.10.4 |
10.10.10.14 |
Response |
pool.ntp.org |
8 |
\ No newline at end of file
+DNS Module
+
+
+
+ | Requests to local DNS server |
+ Requests to external DNS servers |
+ Total DNS requests |
+ Total DNS responses |
+
+
+
+
+ | 71 |
+ 0 |
+ 71 |
+ 84 |
+
+
+
+
+
+
+ | Source |
+ Destination |
+ Resolved IP |
+ Type |
+ URL |
+ Count |
+
+
+
+
+ | 10.10.10.14 |
+ 10.10.10.4 |
+ N/A |
+ Query |
+ mqtt.googleapis.com |
+ 64 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ 173.194.195.206 |
+ Response |
+ mqtt.googleapis.com |
+ 38 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ 2607:f8b0:4001:c11::ce |
+ Response |
+ mqtt.googleapis.com |
+ 32 |
+
+
+ | 10.10.10.14 |
+ 10.10.10.4 |
+ N/A |
+ Query |
+ pool.ntp.org |
+ 7 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ N/A |
+ Response |
+ pool.ntp.org |
+ 4 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ 5.78.89.3 |
+ Response |
+ pool.ntp.org |
+ 2 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ 199.68.201.234 |
+ Response |
+ pool.ntp.org |
+ 2 |
+
+
+ | 10.10.10.4 |
+ 10.10.10.14 |
+ 2607:f8b0:4001:c08::ce |
+ Response |
+ mqtt.googleapis.com |
+ 6 |
+
+
+
+
\ No newline at end of file