bugfix: CPE 2.3 not implemented

This commit is contained in:
José Lopes 2018-10-09 12:41:14 -03:00
parent 6b57c0a080
commit e0da9eb354
3 changed files with 33 additions and 5 deletions

29
netbox-scanner/dac.py Normal file
View File

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

View File

@ -82,7 +82,8 @@ class NetBoxScanner(object):
description = self.get_description( description = self.get_description(
address, nm[host]['hostnames'][0]['name'], address, nm[host]['hostnames'][0]['name'],
nm[host]['osmatch'][0]['osclass'][0]['cpe']) nm[host]['osmatch'][0]['osclass'][0]['cpe'])
except (KeyError, AttributeError, IndexError): except (KeyError, AttributeError, IndexError,
NotImplementedError):
description = self.unknown description = self.unknown
hosts.append((address, description)) hosts.append((address, description))
return hosts return hosts
@ -156,8 +157,7 @@ class NetBoxScanner(object):
hosts = self.scan(net) hosts = self.scan(net)
self.logger('scanned', net=net, hosts=len(hosts)) self.logger('scanned', net=net, hosts=len(hosts))
for host in hosts: for host in hosts:
self.sync_host(host) self.sync_host(host)
for ipv4 in IPv4Network(net): # cleanup for ipv4 in IPv4Network(net): # cleanup
address = str(ipv4) address = str(ipv4)
if not any(h[0]==address for h in hosts): if not any(h[0]==address for h in hosts):
@ -172,5 +172,4 @@ class NetBoxScanner(object):
description=nbhost.description) description=nbhost.description)
except (AttributeError, ValueError): except (AttributeError, ValueError):
pass pass
return True return True

View File

@ -7,7 +7,7 @@ with open('README.md', 'r') as fh:
setuptools.setup( setuptools.setup(
name='netbox-scanner', name='netbox-scanner',
version='0.5.4', version='0.5.5',
author='José Lopes de Oliveira Jr.', author='José Lopes de Oliveira Jr.',
author_email='jlojunior@gmail.com', author_email='jlojunior@gmail.com',
description='A scanner util for NetBox', description='A scanner util for NetBox',