From e1a3533fbebb8806054c5592608a921ea718ed40 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 4 May 2018 09:46:18 -0500 Subject: [PATCH] snmpscan.py: ignore bad DNS config (#8656) When someone has configured reverse dns that points to an incorrect dns hostname, this should revert to IP properly --- snmp-scan.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snmp-scan.py b/snmp-scan.py index 375ebf34eb..f8a03a59ed 100755 --- a/snmp-scan.py +++ b/snmp-scan.py @@ -30,7 +30,7 @@ import json from collections import namedtuple from multiprocessing import Pool from os import path, chdir -from socket import gethostbyname, gethostbyaddr, herror +from socket import gethostbyname, gethostbyaddr, herror, gaierror from subprocess import check_output, CalledProcessError from sys import stdout from time import time @@ -114,10 +114,11 @@ def scan_host(ip): try: try: + # attempt to convert IP to hostname, if anything goes wrong, just use the IP tmp = gethostbyaddr(ip)[0] if gethostbyname(tmp) == ip: # check that forward resolves hostname = tmp - except herror: + except (herror, gaierror): pass try: