Improve test_monitor_tshark.sh output and error handling
- Add progress messages and debug output - Show tshark warnings/errors - Always display counters even if no packets captured - Better handling of empty output - Show sample packets when available - Add DLT check before capture Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a98a255147
commit
cc180b7868
|
|
@ -80,11 +80,32 @@ iw dev "$INTERFACE" info | grep -E "(type|channel)" || echo "Could not verify"
|
||||||
# Check DLT with tshark (capture for 1 second)
|
# Check DLT with tshark (capture for 1 second)
|
||||||
echo ""
|
echo ""
|
||||||
echo "Checking Data Link Type (1 second test capture)..."
|
echo "Checking Data Link Type (1 second test capture)..."
|
||||||
TEST_OUTPUT=$(timeout 1 tshark -i "$INTERFACE" -T fields -e frame.number -e radiotap.present 2>&1)
|
# First check if we can open the interface
|
||||||
|
DLT_CHECK=$(tshark -i "$INTERFACE" -T fields -e frame.number -c 0 2>&1 | head -1)
|
||||||
|
if echo "$DLT_CHECK" | grep -q "Running as"; then
|
||||||
|
echo "$DLT_CHECK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use -c to limit packets and add immediate output, redirect stderr to see warnings
|
||||||
|
# Use a shorter timeout and limit packets to avoid hanging
|
||||||
|
TEST_OUTPUT=$(timeout 2 tshark -i "$INTERFACE" -c 100 -T fields -e frame.number -e radiotap.present 2>&1 || echo "")
|
||||||
|
TEST_EXIT_CODE=$?
|
||||||
|
|
||||||
|
# Show any warnings/errors from tshark
|
||||||
|
echo "$TEST_OUTPUT" | grep -E "(Running as|tshark:|Warning|Error)" || true
|
||||||
|
|
||||||
|
# Count packets (lines starting with a number)
|
||||||
PACKET_COUNT=$(echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
PACKET_COUNT=$(echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
||||||
PLCP_COUNT=$(echo "$TEST_OUTPUT" | grep -E '^[0-9]+.*[0-9]' | wc -l || echo "0")
|
# Count lines with both frame.number and radiotap.present (non-empty second field)
|
||||||
echo "$TEST_OUTPUT" | tail -5 || true
|
PLCP_COUNT=$(echo "$TEST_OUTPUT" | awk -F'\t' 'NF >= 2 && $1 != "" && $2 != "" && $2 != "0" && $2 != "-" {count++} END {print count+0}' || echo "0")
|
||||||
echo "Captured $PACKET_COUNT packet(s) in 1 second"
|
|
||||||
|
# Show sample output
|
||||||
|
if [ "$PACKET_COUNT" -gt 0 ]; then
|
||||||
|
echo "Sample packets:"
|
||||||
|
echo "$TEST_OUTPUT" | grep -E '^[0-9]+' | head -3
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Captured $PACKET_COUNT packet(s) in test capture"
|
||||||
if [ "$PLCP_COUNT" -gt 0 ]; then
|
if [ "$PLCP_COUNT" -gt 0 ]; then
|
||||||
echo "PLCP headers: $PLCP_COUNT (radiotap present)"
|
echo "PLCP headers: $PLCP_COUNT (radiotap present)"
|
||||||
else
|
else
|
||||||
|
|
@ -97,6 +118,7 @@ echo "Press Ctrl+C to stop early"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Capture for specified duration and count packets
|
# Capture for specified duration and count packets
|
||||||
|
echo "Capturing packets for $DURATION seconds..."
|
||||||
CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
||||||
-e frame.number \
|
-e frame.number \
|
||||||
-e frame.time \
|
-e frame.time \
|
||||||
|
|
@ -107,16 +129,28 @@ CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
||||||
-e wlan.fc.type_subtype \
|
-e wlan.fc.type_subtype \
|
||||||
-e radiotap.present \
|
-e radiotap.present \
|
||||||
2>&1)
|
2>&1)
|
||||||
|
CAPTURE_EXIT_CODE=$?
|
||||||
|
|
||||||
# Display first 50 lines of output
|
# Show any warnings/errors
|
||||||
echo "$CAPTURE_OUTPUT" | head -50
|
echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | head -5 || true
|
||||||
|
|
||||||
# Count total packets captured
|
# Display first 50 lines of packet output
|
||||||
|
PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' || true)
|
||||||
|
if [ -n "$PACKET_LINES" ]; then
|
||||||
|
echo ""
|
||||||
|
echo "Sample packets (first 20):"
|
||||||
|
echo "$PACKET_LINES" | head -20
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo "(No packets captured)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Count total packets captured (lines starting with a number)
|
||||||
FINAL_COUNT=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
FINAL_COUNT=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
||||||
|
|
||||||
# Count packets with PLCP headers (radiotap present)
|
# Count packets with PLCP headers (radiotap present)
|
||||||
# radiotap.present field is the 8th field (after frame.number, frame.time, wlan.sa, wlan.da, wlan.fc.type, wlan.fc.subtype, wlan.fc.type_subtype)
|
# radiotap.present field is the 8th field (after frame.number, frame.time, wlan.sa, wlan.da, wlan.fc.type, wlan.fc.subtype, wlan.fc.type_subtype)
|
||||||
PLCP_COUNT=$(echo "$CAPTURE_OUTPUT" | awk -F'\t' 'NF >= 8 && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0")
|
PLCP_COUNT=$(echo "$CAPTURE_OUTPUT" | awk -F'\t' 'NF >= 8 && $1 != "" && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0")
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "=== Capture complete ==="
|
echo "=== Capture complete ==="
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue