I want to extract the domain name from DNS packets (request/response) from .pcapng file. the following code what I used
def extract_domain_name(pkt):
try:
if pkt.dns.qry_name:
#print (pkt.ip.src, pkt.dns.qry_name)
return pkt.dns.qry_name
except AttributeError as e:
#ignore packets that aren't DNS Request
pass
try:
if pkt.dns.resp_name:
print (pkt.ip.src, pkt.dns.resp_name)
return pkt.dns.resp_name
except AttributeError as e:
#ignore packets that aren't DNS Response
pass
def process_pcapng_file(filename):
# Open the pcapng file
cap = pyshark.FileCapture(filename)
# Extract the domain names from the DNS packets
domains = set()
for pkt in cap:
#print (pkt)
if 'DNS' in pkt:
#domain = pkt.dns.qry_name
domain = extract_domain_name(pkt)
if domain is not None:
domains.add(domain)
it only extract the domain name from query packets not from query and response. what could the problem? However,
I tried to use if pkt.dns.resp_name:
without try:
and I got AttributeError