From e0da9eb3546f2810601dfdbf6f7fd17e28b67e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lopes?= Date: Tue, 9 Oct 2018 12:41:14 -0300 Subject: [PATCH] bugfix: CPE 2.3 not implemented --- netbox-scanner/dac.py | 29 +++++++++++++++++++++++++++++ netbox-scanner/nbscan.py | 7 +++---- setup.py | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 netbox-scanner/dac.py diff --git a/netbox-scanner/dac.py b/netbox-scanner/dac.py new file mode 100644 index 0000000..5cf588c --- /dev/null +++ b/netbox-scanner/dac.py @@ -0,0 +1,29 @@ +import re + +from config import NETWORKS + + +def parser(networks): + '''Parses a list of networks in CIDR notation. + + :param networks: a list of networks like ['10.0.0.0/8',...] + :return: False if parsing is OK, or a string with duplicated + or mistyped networks. + ''' + ipv4 = re.compile(r'^((2([0-4][0-9]|5[0-5])|1?[0-9]?[0-9])\.){3}(2([0-4][0-9]|5[0-5])|1?[0-9]?[0-9])\/(3[012]|[12]?[0-9])$') + duplicated = set([x for x in networks if networks.count(x)>1]) + if duplicated: + return ', '.join(duplicated) + for net in networks: + if not re.match(ipv4, net): + return net + return False + +nets = NETWORKS +nets.sort() + +p = parser(nets) +if not p: + print(nets) +else: + print('ERROR: {}'.format(p)) diff --git a/netbox-scanner/nbscan.py b/netbox-scanner/nbscan.py index 6988aaf..4773468 100644 --- a/netbox-scanner/nbscan.py +++ b/netbox-scanner/nbscan.py @@ -82,7 +82,8 @@ class NetBoxScanner(object): description = self.get_description( address, nm[host]['hostnames'][0]['name'], nm[host]['osmatch'][0]['osclass'][0]['cpe']) - except (KeyError, AttributeError, IndexError): + except (KeyError, AttributeError, IndexError, + NotImplementedError): description = self.unknown hosts.append((address, description)) return hosts @@ -156,8 +157,7 @@ class NetBoxScanner(object): hosts = self.scan(net) self.logger('scanned', net=net, hosts=len(hosts)) for host in hosts: - self.sync_host(host) - + self.sync_host(host) for ipv4 in IPv4Network(net): # cleanup address = str(ipv4) if not any(h[0]==address for h in hosts): @@ -172,5 +172,4 @@ class NetBoxScanner(object): description=nbhost.description) except (AttributeError, ValueError): pass - return True diff --git a/setup.py b/setup.py index 00a06b4..e1a5755 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md', 'r') as fh: setuptools.setup( name='netbox-scanner', - version='0.5.4', + version='0.5.5', author='José Lopes de Oliveira Jr.', author_email='jlojunior@gmail.com', description='A scanner util for NetBox',