Skip to content

Commit

Permalink
Merge pull request #14 from restena-pyg/fix_unknown_host
Browse files Browse the repository at this point in the history
Fix unknown host
  • Loading branch information
jertel authored Jun 10, 2024
2 parents 9828dd3 + a4176fa commit 1c48974
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/dmarc2logstash.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,17 @@ def parse(jsonOutputFile, xml, subject):

def lookupHostFromIp(ip):
host = ip
hosts = socket.gethostbyaddr(ip)
if len(hosts) > 0:
host = hosts[0]
segments = host.split('.')
if len(segments) > 2:
host = segments[-2] + "." + segments[-1]
try:
hosts = socket.gethostbyaddr(ip)
if len(hosts) > 0:
host = hosts[0]
segments = host.split('.')
if len(segments) > 2:
host = segments[-2] + "." + segments[-1]
except socket.herror:
pass
except Exception as e:
log.warning(f"Unable to lookup hostname for IP; ip={ip}; error={e}")

return host

Expand Down

0 comments on commit 1c48974

Please sign in to comment.