if len(chunks) == 3:
# For a "query" entry's clientip:clientport:id field.
- id = int(chunks[2], 16)
- words[i] += f" (id {id})"
+ packet_id = int(chunks[2], 16)
+ words[i] += f" (id {packet_id})"
def decode_ip(words : list, i : int):
r"""
"""
qt = words[i]
- words[i] = query_type.get(int(qt), qt)
+ words[i] = query_type_name.get(int(qt), qt)
def handle_dnscache_log(line : str) -> Optional[str]:
r"""
if not match:
return None
- (timestamp, ip, port, id, code, type, name) = match.groups()
+ (timestamp, ip, port, request_id, code, query_type, name) = match.groups()
ip = convert_ip(ip)
port = int(port, 16)
- id = int(id, 16)
+ request_id = int(request_id, 16)
# Convert the "type" field to a human-readable record type name
# using the query_type dictionary. If the right name isn't present
# in the dictionary, we use the (decimal) type id instead.
- type = int(type, 16) # "001c" -> 28
- type = query_type.get(type, type) # 28 -> "aaaa"
+ query_type = int(query_type, 16) # "001c" -> 28
+ query_type = query_type_name.get(query_type, type) # 28 -> "aaaa"
line_tpl = "{timestamp} "
reason = query_drop_reason[code]
if code == "+":
- line_tpl += "sent response to {ip}:{port} (id {id}): {type} {name}"
+ line_tpl += "sent response to {ip}:{port} (id {request_id}): "
+ line_tpl += "{query_type} {name}"
else:
line_tpl += "dropped query ({reason}) from {ip}:{port}"
if code != "/":
# If the query can actually be parsed, the log line is a
# bit more informative than it would have been otherwise.
- line_tpl += " (id {id}): {type} {name}"
+ line_tpl += " (id {request_id}): {query_type} {name}"
return line_tpl.format(timestamp=timestamp,
reason=reason,
ip=ip,
port=port,
- id=id,
- type=type,
+ request_id=request_id,
+ query_type=query_type,
name=name)