Fix KEEP_PCAP not working with sudo
- Add --keep-pcap command-line flag that works with sudo - Environment variable KEEP_PCAP still works with 'sudo -E' - Usage: sudo ./test_monitor_tshark.sh wlan0 36 10 --keep-pcap - Or: KEEP_PCAP=1 sudo -E ./test_monitor_tshark.sh wlan0 36 10 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ba4fb72a40
commit
bc282a348a
|
|
@ -1,12 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Test script to verify monitor mode works with tshark
|
# Test script to verify monitor mode works with tshark
|
||||||
# Usage: ./test_monitor_tshark.sh [interface] [channel] [duration_seconds]
|
# Usage: ./test_monitor_tshark.sh [interface] [channel] [duration_seconds] [--keep-pcap]
|
||||||
|
# Or: KEEP_PCAP=1 sudo -E ./test_monitor_tshark.sh [interface] [channel] [duration_seconds]
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
INTERFACE="${1:-wlan0}"
|
# Parse arguments
|
||||||
CHANNEL="${2:-36}"
|
KEEP_PCAP_FLAG=""
|
||||||
DURATION="${3:-10}" # Default 10 seconds, minimum 1 second
|
ARGS=()
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [ "$arg" = "--keep-pcap" ] || [ "$arg" = "-k" ]; then
|
||||||
|
KEEP_PCAP_FLAG="1"
|
||||||
|
else
|
||||||
|
ARGS+=("$arg")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
INTERFACE="${ARGS[0]:-wlan0}"
|
||||||
|
CHANNEL="${ARGS[1]:-36}"
|
||||||
|
DURATION="${ARGS[2]:-10}" # Default 10 seconds, minimum 1 second
|
||||||
|
|
||||||
|
# Check for KEEP_PCAP environment variable or flag
|
||||||
|
if [ -n "$KEEP_PCAP_FLAG" ]; then
|
||||||
|
KEEP_PCAP="1"
|
||||||
|
elif [ -z "${KEEP_PCAP:-}" ]; then
|
||||||
|
KEEP_PCAP=""
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure minimum 1 second
|
# Ensure minimum 1 second
|
||||||
if [ "$DURATION" -lt 1 ]; then
|
if [ "$DURATION" -lt 1 ]; then
|
||||||
|
|
@ -189,11 +208,12 @@ CAPTURE_OUTPUT=$(tshark -q -r "$TEMP_PCAP" -n -T fields \
|
||||||
2>/dev/null || true)
|
2>/dev/null || true)
|
||||||
|
|
||||||
# Clean up temp file (unless KEEP_PCAP is set)
|
# Clean up temp file (unless KEEP_PCAP is set)
|
||||||
if [ -z "${KEEP_PCAP:-}" ]; then
|
if [ -z "$KEEP_PCAP" ]; then
|
||||||
echo "Cleaning up temporary pcap file: $TEMP_PCAP"
|
echo "Cleaning up temporary pcap file: $TEMP_PCAP"
|
||||||
rm -f "$TEMP_PCAP"
|
rm -f "$TEMP_PCAP"
|
||||||
else
|
else
|
||||||
echo "Keeping temporary pcap file: $TEMP_PCAP"
|
echo "Keeping temporary pcap file: $TEMP_PCAP"
|
||||||
|
echo " (Use: tshark -r $TEMP_PCAP to analyze)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Force output flush
|
# Force output flush
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue