Compare commits

..

No commits in common. "8d607a5f66bc8a1e42f8b3687e8ad0053e75848c" and "fb7dca0137dc101fa8e3327c23539ed3f876ec3b" have entirely different histories.

1 changed files with 12 additions and 28 deletions

View File

@ -97,13 +97,10 @@ PACKET_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0")
# Count lines with both frame.number and radiotap.present (non-empty second field) # Count lines with both frame.number and radiotap.present (non-empty second field)
PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 2 && $1 != "" && $2 != "" && $2 != "0" && $2 != "-" {count++} END {print count+0}' || echo "0") PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 2 && $1 != "" && $2 != "" && $2 != "0" && $2 != "-" {count++} END {print count+0}' || echo "0")
# Show sample output with better formatting # Show sample output
if [ "$PACKET_COUNT" -gt 0 ]; then if [ "$PACKET_COUNT" -gt 0 ]; then
echo "Sample packets:" echo "Sample packets:"
echo "$PACKET_LINES" | head -5 | awk -F'\t' '{ echo "$PACKET_LINES" | head -3
radiotap = ($2 == "1" || $2 == "1.0") ? "yes" : "no"
printf " Frame %s: PLCP header (radiotap) = %s\n", $1, radiotap
}'
fi fi
echo "" echo ""
@ -122,7 +119,7 @@ echo ""
# Capture for specified duration and count packets # Capture for specified duration and count packets
echo "Capturing packets for $DURATION seconds..." echo "Capturing packets for $DURATION seconds..."
# Run capture with timeout # Run capture in background and show progress
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 \
@ -135,30 +132,25 @@ CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
2>&1) 2>&1)
CAPTURE_EXIT_CODE=$? CAPTURE_EXIT_CODE=$?
# Force output flush # Immediately show stats after capture completes
sync
# Show stats immediately after capture completes
echo "" echo ""
echo "=== Capture Statistics ===" echo "=== Capture Statistics ==="
# Show any warnings/errors (but not the "Running as root" or "Capturing" messages) # Show any warnings/errors
WARNINGS=$(echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | grep -v -E "(Running as|Capturing)" | head -5 || true) WARNINGS=$(echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | head -5 || true)
if [ -n "$WARNINGS" ]; then if [ -n "$WARNINGS" ]; then
echo "$WARNINGS" echo "$WARNINGS"
echo ""
fi fi
# Count total packets captured (lines starting with a number followed by tab) # Count total packets captured (lines starting with a number)
# Filter out lines like "100 packets captured" which don't have tabs PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' || true)
PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+\t' || true)
FINAL_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0") FINAL_COUNT=$(echo "$PACKET_LINES" | 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 "$PACKET_LINES" | awk -F'\t' 'NF >= 8 && $1 != "" && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0") PLCP_COUNT=$(echo "$PACKET_LINES" | awk -F'\t' 'NF >= 8 && $1 != "" && $8 != "" && $8 != "0" && $8 != "-" {count++} END {print count+0}' || echo "0")
# Display stats immediately - always show these # Display stats immediately
echo "Total packets captured: $FINAL_COUNT" echo "Total packets captured: $FINAL_COUNT"
echo "PLCP headers: $PLCP_COUNT" echo "PLCP headers: $PLCP_COUNT"
if [ "$FINAL_COUNT" -gt 0 ]; then if [ "$FINAL_COUNT" -gt 0 ]; then
@ -168,18 +160,10 @@ if [ "$FINAL_COUNT" -gt 0 ]; then
fi fi
echo "" echo ""
# Display sample packets with readable format # Display sample packets
if [ -n "$PACKET_LINES" ] && [ "$FINAL_COUNT" -gt 0 ]; then if [ -n "$PACKET_LINES" ] && [ "$FINAL_COUNT" -gt 0 ]; then
echo "Sample packets (first 10):" echo "Sample packets (first 20):"
echo "$PACKET_LINES" | head -10 | awk -F'\t' '{ echo "$PACKET_LINES" | head -20
sa = ($3 != "" && $3 != "-") ? $3 : "N/A"
da = ($4 != "" && $4 != "-") ? $4 : "N/A"
type = ($5 != "" && $5 != "-") ? $5 : "N/A"
subtype = ($6 != "" && $6 != "-") ? $6 : "N/A"
radiotap = ($8 == "1" || $8 == "1.0") ? "yes" : (($8 != "" && $8 != "-") ? "no" : "N/A")
printf " Frame %s: SA=%s, DA=%s, type=%s/%s, PLCP=%s\n",
$1, sa, da, type, subtype, radiotap
}'
echo "" echo ""
else else
echo "(No packets captured)" echo "(No packets captured)"