2020-10-29 22:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# 2020 Nico Schottelius (nico-cdist at schottelius.org)
|
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import logging
|
2021-04-22 06:55:14 +00:00
|
|
|
import sys
|
2020-10-29 22:16:08 +00:00
|
|
|
|
|
|
|
log = logging.getLogger("scan")
|
|
|
|
|
2021-04-22 07:29:53 +00:00
|
|
|
# CLI processing is defined outside of the main scan class to handle
|
|
|
|
# non-available optional scapy dependency (instead of crashing mid-flight).
|
2020-10-29 22:16:08 +00:00
|
|
|
def commandline(args):
|
|
|
|
log.debug(args)
|
|
|
|
|
2021-04-22 07:29:53 +00:00
|
|
|
# Check if we have the optional scapy dependency available.
|
2020-10-29 22:16:08 +00:00
|
|
|
try:
|
|
|
|
import cdist.scan.scan as scan
|
|
|
|
except ModuleNotFoundError:
|
2021-04-22 07:29:53 +00:00
|
|
|
log.error('cdist scan requires scapy to be installed. Exiting.')
|
2021-04-22 06:55:14 +00:00
|
|
|
sys.exit(1)
|
2020-10-29 22:16:08 +00:00
|
|
|
|
2021-04-22 07:29:53 +00:00
|
|
|
# Default operation mode.
|
2020-10-29 22:16:08 +00:00
|
|
|
if not args.mode:
|
2021-04-22 07:29:53 +00:00
|
|
|
# By default scan and trigger, but do not call any action.
|
2020-11-03 05:43:57 +00:00
|
|
|
args.mode = ['scan', 'trigger', ]
|
2020-10-29 22:16:08 +00:00
|
|
|
|
2021-04-22 07:29:53 +00:00
|
|
|
# We run each component in a separate process since they
|
|
|
|
# must not block on each other.
|
|
|
|
processes = []
|
|
|
|
|
2020-10-29 22:16:08 +00:00
|
|
|
if 'trigger' in args.mode:
|
2021-04-22 07:29:53 +00:00
|
|
|
t = scan.Trigger(interfaces=args.interfaces, sleeptime=args.trigger_delay)
|
2020-10-29 22:16:08 +00:00
|
|
|
t.start()
|
|
|
|
processes.append(t)
|
|
|
|
log.debug("Trigger started")
|
|
|
|
|
|
|
|
if 'scan' in args.mode:
|
|
|
|
s = scan.Scanner(interfaces=args.interfaces, args=args)
|
|
|
|
s.start()
|
|
|
|
processes.append(s)
|
|
|
|
log.debug("Scanner started")
|
|
|
|
|
|
|
|
for process in processes:
|
|
|
|
process.join()
|