mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-15 22:51:37 -07:00
nmap count in logs
This commit is contained in:
+15
-7
@@ -526,8 +526,6 @@ def main ():
|
|||||||
|
|
||||||
# Reporting
|
# Reporting
|
||||||
if cycle in check_report:
|
if cycle in check_report:
|
||||||
send_notifications()
|
|
||||||
|
|
||||||
# Check if new devices need to be scanned with Nmap
|
# Check if new devices need to be scanned with Nmap
|
||||||
if NMAP_ACTIVE:
|
if NMAP_ACTIVE:
|
||||||
sql.execute ("""SELECT eve_IP as dev_LastIP, eve_MAC as dev_MAC FROM Events_Devices
|
sql.execute ("""SELECT eve_IP as dev_LastIP, eve_MAC as dev_MAC FROM Events_Devices
|
||||||
@@ -540,6 +538,9 @@ def main ():
|
|||||||
|
|
||||||
performNmapScan(rows)
|
performNmapScan(rows)
|
||||||
|
|
||||||
|
# send all configured notifications
|
||||||
|
send_notifications()
|
||||||
|
|
||||||
# clean up the DB once a day
|
# clean up the DB once a day
|
||||||
if last_cleanup + datetime.timedelta(hours = 24) < time_started:
|
if last_cleanup + datetime.timedelta(hours = 24) < time_started:
|
||||||
last_cleanup = time_started
|
last_cleanup = time_started
|
||||||
@@ -1584,32 +1585,39 @@ def performNmapScan(devicesToScan):
|
|||||||
|
|
||||||
timeoutSec = NMAP_TIMEOUT
|
timeoutSec = NMAP_TIMEOUT
|
||||||
|
|
||||||
|
devTotal = len(devicesToScan)
|
||||||
|
|
||||||
updateState("Scan: Nmap")
|
updateState("Scan: Nmap")
|
||||||
|
|
||||||
file_print('[', timeNow(), '] Scan: Nmap for max ', str(timeoutSec), 's ('+ str(round(int(timeoutSec) / 60, 1)) +'min) per device')
|
file_print('[', timeNow(), '] Scan: Nmap for max ', str(timeoutSec), 's ('+ str(round(int(timeoutSec) / 60, 1)) +'min) per device')
|
||||||
|
|
||||||
file_print(" Estimated max delay: ", (len(devicesToScan) * int(timeoutSec)), 's ', '(', round((len(devicesToScan) * int(timeoutSec))/60,1) , 'min)' )
|
file_print(" Estimated max delay: ", (devTotal * int(timeoutSec)), 's ', '(', round((devTotal * int(timeoutSec))/60,1) , 'min)' )
|
||||||
|
|
||||||
|
devIndex = 0
|
||||||
for device in devicesToScan:
|
for device in devicesToScan:
|
||||||
# Execute command
|
# Execute command
|
||||||
output = ""
|
output = ""
|
||||||
# prepare arguments from user supplied ones
|
# prepare arguments from user supplied ones
|
||||||
nmapArgs = ['nmap'] + NMAP_ARGS.split() + [device["dev_LastIP"]]
|
nmapArgs = ['nmap'] + NMAP_ARGS.split() + [device["dev_LastIP"]]
|
||||||
|
|
||||||
|
progress = ' (' + str(devIndex) + '/' + str(devTotal) + ')'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# try runnning a subprocess with a forced (timeout + 30 seconds) in case the subprocess hangs
|
# try runnning a subprocess with a forced (timeout + 30 seconds) in case the subprocess hangs
|
||||||
output = subprocess.check_output (nmapArgs, universal_newlines=True, stderr=subprocess.STDOUT, timeout=(timeoutSec + 30))
|
output = subprocess.check_output (nmapArgs, universal_newlines=True, stderr=subprocess.STDOUT, timeout=(timeoutSec + 30))
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
# An error occured, handle it
|
# An error occured, handle it
|
||||||
file_print(e.output)
|
file_print(e.output)
|
||||||
file_print(" Error - Nmap Scan - check logs")
|
file_print(" Error - Nmap Scan - check logs", progress)
|
||||||
except subprocess.TimeoutExpired as timeErr:
|
except subprocess.TimeoutExpired as timeErr:
|
||||||
file_print(' Nmap TIMEOUT - the process forcefully terminated as timeout reached for ', device["dev_LastIP"])
|
file_print(' Nmap TIMEOUT - the process forcefully terminated as timeout reached for ', device["dev_LastIP"], progress)
|
||||||
|
|
||||||
if output == "": # check if the subprocess failed
|
if output == "": # check if the subprocess failed
|
||||||
file_print('[', timeNow(), '] Scan: Nmap FAIL - check logs')
|
file_print('[', timeNow(), '] Scan: Nmap FAIL for ', device["dev_LastIP"], progress ,' check logs for details')
|
||||||
else:
|
else:
|
||||||
file_print('[', timeNow(), '] Scan: Nmap SUCCESS for ', device["dev_LastIP"])
|
file_print('[', timeNow(), '] Scan: Nmap SUCCESS for ', device["dev_LastIP"], progress)
|
||||||
|
|
||||||
|
devIndex += 1
|
||||||
|
|
||||||
# check the last run output
|
# check the last run output
|
||||||
newLines = output.split('\n')
|
newLines = output.split('\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user