mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 01:26:11 -08:00
@@ -64,7 +64,8 @@
|
|||||||
"name": "subnets",
|
"name": "subnets",
|
||||||
"type": "setting",
|
"type": "setting",
|
||||||
"value": "SCAN_SUBNETS",
|
"value": "SCAN_SUBNETS",
|
||||||
"base64": true
|
"base64": true,
|
||||||
|
"timeoutMultiplier": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": [
|
"settings": [
|
||||||
@@ -387,6 +388,34 @@
|
|||||||
"string": "Arguments to run arps-scan with. Recommended and tested only with the setting: <br/> <code>sudo arp-scan --ignoredups --retry=6</code>."
|
"string": "Arguments to run arps-scan with. Recommended and tested only with the setting: <br/> <code>sudo arp-scan --ignoredups --retry=6</code>."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"function": "DURATION",
|
||||||
|
"type": {
|
||||||
|
"dataType": "integer",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"elementType": "input",
|
||||||
|
"elementOptions": [{ "type": "number" }],
|
||||||
|
"transformers": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default_value": 0,
|
||||||
|
"options": [],
|
||||||
|
"localized": ["name", "description"],
|
||||||
|
"name": [
|
||||||
|
{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string": "Discovery duration"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": [
|
||||||
|
{
|
||||||
|
"language_code": "en_us",
|
||||||
|
"string": "If <code>DURATION</code> is not <code>0</code>, the scan runs repeatedly per interface for that many seconds. <strong>Important:</strong> <code>RUN_TIMEOUT</code> must be greater than <code>DURATION</code>, otherwise the scan will fail."
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"database_column_definitions": [
|
"database_column_definitions": [
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import pathlib
|
import pathlib
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
@@ -150,16 +151,28 @@ def execute_arpscan_on_interface(interface):
|
|||||||
# Prepare command arguments
|
# Prepare command arguments
|
||||||
arpscan_args = get_setting_value('ARPSCAN_ARGS').split() + interface.split()
|
arpscan_args = get_setting_value('ARPSCAN_ARGS').split() + interface.split()
|
||||||
|
|
||||||
# Execute command
|
# Optional duration in seconds (0 = run once)
|
||||||
try:
|
try:
|
||||||
# try running a subprocess safely
|
scan_duration = int(get_setting_value('ARPSCAN_DURATION'))
|
||||||
result = subprocess.check_output(arpscan_args, universal_newlines=True)
|
except Exception:
|
||||||
except subprocess.CalledProcessError as e:
|
scan_duration = 0 # default: single run
|
||||||
# An error occurred, handle it
|
|
||||||
error_type = type(e).__name__ # Capture the error type
|
|
||||||
result = ""
|
|
||||||
|
|
||||||
return result
|
results = []
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
result = subprocess.check_output(arpscan_args, universal_newlines=True)
|
||||||
|
results.append(result)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
result = ""
|
||||||
|
# stop looping if duration not set or expired
|
||||||
|
if scan_duration == 0 or (time.time() - start_time) > scan_duration:
|
||||||
|
break
|
||||||
|
time.sleep(2) # short delay between scans
|
||||||
|
|
||||||
|
# concatenate all outputs (for regex parsing)
|
||||||
|
return "\n".join(results)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user