[scanner] add minimal error handling, consolidate CLI args processing

This commit is contained in:
fnux 2021-04-22 09:29:53 +02:00
commit a4464209b6
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12
3 changed files with 37 additions and 63 deletions

View file

@ -24,26 +24,29 @@ import sys
log = logging.getLogger("scan")
# define this outside of the class to not handle scapy import errors by default
# CLI processing is defined outside of the main scan class to handle
# non-available optional scapy dependency (instead of crashing mid-flight).
def commandline(args):
log.debug(args)
# Check if we have the optional scapy dependency available.
try:
import cdist.scan.scan as scan
except ModuleNotFoundError:
print('cdist scan requires scapy to be installed! Exiting.',
file=sys.stderr)
log.error('cdist scan requires scapy to be installed. Exiting.')
sys.exit(1)
processes = []
# Default operation mode.
if not args.mode:
# By default scan and trigger, but do not call any action
# By default scan and trigger, but do not call any action.
args.mode = ['scan', 'trigger', ]
# We run each component in a separate process since they
# must not block on each other.
processes = []
if 'trigger' in args.mode:
t = scan.Trigger(interfaces=args.interfaces)
t = scan.Trigger(interfaces=args.interfaces, sleeptime=args.trigger_delay)
t.start()
processes.append(t)
log.debug("Trigger started")