diff --git a/test_monitor_tshark.sh b/test_monitor_tshark.sh index 11e33b3..6bdfd99 100755 --- a/test_monitor_tshark.sh +++ b/test_monitor_tshark.sh @@ -1,12 +1,31 @@ #!/bin/bash # 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 -INTERFACE="${1:-wlan0}" -CHANNEL="${2:-36}" -DURATION="${3:-10}" # Default 10 seconds, minimum 1 second +# Parse arguments +KEEP_PCAP_FLAG="" +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 if [ "$DURATION" -lt 1 ]; then @@ -189,11 +208,12 @@ CAPTURE_OUTPUT=$(tshark -q -r "$TEMP_PCAP" -n -T fields \ 2>/dev/null || true) # 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" rm -f "$TEMP_PCAP" else echo "Keeping temporary pcap file: $TEMP_PCAP" + echo " (Use: tshark -r $TEMP_PCAP to analyze)" fi # Force output flush