Show capture statistics immediately after capture completes
- Display stats right after 'Capturing packets' line completes - Show packet count, PLCP count, and packet rate immediately - Move sample packets display after stats - Reorganize output for better readability Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
b80a9d818b
commit
fb7dca0137
|
|
@ -118,6 +118,8 @@ echo ""
|
|||
|
||||
# Capture for specified duration and count packets
|
||||
echo "Capturing packets for $DURATION seconds..."
|
||||
|
||||
# Run capture in background and show progress
|
||||
CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
||||
-e frame.number \
|
||||
-e frame.time \
|
||||
|
|
@ -130,32 +132,45 @@ CAPTURE_OUTPUT=$(timeout "$DURATION" tshark -i "$INTERFACE" -n -T fields \
|
|||
2>&1)
|
||||
CAPTURE_EXIT_CODE=$?
|
||||
|
||||
# Show any warnings/errors
|
||||
echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | head -5 || true
|
||||
# Immediately show stats after capture completes
|
||||
echo ""
|
||||
echo "=== Capture Statistics ==="
|
||||
|
||||
# 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)"
|
||||
# Show any warnings/errors
|
||||
WARNINGS=$(echo "$CAPTURE_OUTPUT" | grep -E "(tshark:|Warning|Error)" | head -5 || true)
|
||||
if [ -n "$WARNINGS" ]; then
|
||||
echo "$WARNINGS"
|
||||
fi
|
||||
|
||||
# Count total packets captured (lines starting with a number)
|
||||
FINAL_COUNT=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' | wc -l || echo "0")
|
||||
PACKET_LINES=$(echo "$CAPTURE_OUTPUT" | grep -E '^[0-9]+' || true)
|
||||
FINAL_COUNT=$(echo "$PACKET_LINES" | wc -l || echo "0")
|
||||
|
||||
# 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)
|
||||
PLCP_COUNT=$(echo "$CAPTURE_OUTPUT" | 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")
|
||||
|
||||
echo ""
|
||||
echo "=== Capture complete ==="
|
||||
# Display stats immediately
|
||||
echo "Total packets captured: $FINAL_COUNT"
|
||||
echo "PLCP headers: $PLCP_COUNT"
|
||||
if [ "$FINAL_COUNT" -gt 0 ]; then
|
||||
# Calculate rate
|
||||
RATE=$(awk "BEGIN {printf \"%.1f\", $FINAL_COUNT / $DURATION}")
|
||||
echo "Packet rate: $RATE packets/second"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Display sample packets
|
||||
if [ -n "$PACKET_LINES" ] && [ "$FINAL_COUNT" -gt 0 ]; then
|
||||
echo "Sample packets (first 20):"
|
||||
echo "$PACKET_LINES" | head -20
|
||||
echo ""
|
||||
else
|
||||
echo "(No packets captured)"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "=== Summary ==="
|
||||
if [ "$FINAL_COUNT" -gt 0 ]; then
|
||||
echo "✓ Monitor mode is working! Captured $FINAL_COUNT packet(s)"
|
||||
if [ "$PLCP_COUNT" -gt 0 ]; then
|
||||
|
|
|
|||
Loading…
Reference in New Issue