Skip to content

Commit

Permalink
Reverse-lookup cache improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rodpayne committed Mar 30, 2024
1 parent 041296b commit dc53ca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion parsedmarc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
MAGIC_XML = b"\x3c\x3f\x78\x6d\x6c\x20"
MAGIC_JSON = b"\7b"

IP_ADDRESS_CACHE = ExpiringDict(max_len=10000, max_age_seconds=1800)
IP_ADDRESS_CACHE = ExpiringDict(max_len=10000, max_age_seconds=14400)
REVERSE_DNS_MAP = dict()


Expand Down
14 changes: 7 additions & 7 deletions parsedmarc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def get_reverse_dns(ip_address, cache=None, nameservers=None, timeout=2.0):
nameservers=nameservers,
timeout=timeout)[0]

except dns.exception.DNSException:
except dns.exception.DNSException as e:
logger.warning(f"get_reverse_dns({ip_address}) exception: {e}")
pass

return hostname
Expand Down Expand Up @@ -379,10 +380,6 @@ def get_ip_address_info(ip_address, ip_db_path=None,
if info:
logger.debug(f"IP address {ip_address} was found in cache")
return info
else:
logger.debug(f"IP address {ip_address} not found in cache")
else:
logger.debug("IP address cache was not specified")
info = OrderedDict()
info["ip_address"] = ip_address
if offline:
Expand All @@ -407,8 +404,11 @@ def get_ip_address_info(ip_address, ip_db_path=None,
info["type"] = service["type"]
info["name"] = service["name"]

if cache is not None:
cache[ip_address] = info
if cache is not None:
cache[ip_address] = info
logger.debug(f"IP address {ip_address} added to cache")
else:
logger.debug(f"IP address {ip_address} reverse_dns not found")

return info

Expand Down

0 comments on commit dc53ca2

Please sign in to comment.