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
This commit is contained in:
Tony Murray 2018-05-04 09:46:18 -05:00 committed by GitHub
parent 4140796807
commit e1a3533fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -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: