mirror of
https://github.com/lopes/netbox-scanner.git
synced 2025-07-21 04:44:37 +02:00
bugfix: CPE 2.3 not implemented
This commit is contained in:
parent
6b57c0a080
commit
e0da9eb354
29
netbox-scanner/dac.py
Normal file
29
netbox-scanner/dac.py
Normal 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))
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user