From afd8251198ab3932a32eafc10b707109d68338f2 Mon Sep 17 00:00:00 2001 From: yaro Date: Wed, 9 Apr 2025 13:58:15 -0500 Subject: [PATCH] Initial upload. --- runtest.sh | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 runtest.sh diff --git a/runtest.sh b/runtest.sh new file mode 100644 index 0000000..cb7a8f5 --- /dev/null +++ b/runtest.sh @@ -0,0 +1,93 @@ +#!/bin/bash + +SCRIPT_DIRECTORY="/home/yaro/scripts" +RECIPIENT=conrad.nelson@nebraska.gov +NUM_TESTS=1 +NUM_SAMPLES=5 +TIME_BETWEEN=15m +BOOT_ID=$(cat /proc/sys/kernel/random/boot_id) +TEST_FILE="/home/yaro/${BOOT_ID}-speedtest.csv" +PING_COUNT=25 +PING_TARGET=1.1.1.1 +KISMET_LOG_DIR="/home/yaro/kismet_logs" + +ENRICHED_FILE="${TEST_FILE%}+rf.csv" + +# Function to get current TX failed count +get_tx_failed() { + iw dev wlan0 station dump | awk '/tx failed/ {print $3}' +} + +freq_to_channel() { + local freq=$1 + local channel=0 + + if [ "$freq" -ge 2412 ] && [ "$freq" -le 2472 ]; then + channel=$(( (freq - 2407) / 5 )) + elif [ "$freq" -eq 2484 ]; then + channel=14 + elif [ "$freq" -ge 5180 ] && [ "$freq" -le 5825 ]; then + channel=$(( (freq - 5000) / 5 )) + else + channel="Unknown" + fi + + echo "$channel" +} + +# Start test email +echo -e "Subject: Test ${BOOT_ID} Started\n\nThis is to inform you that the tests have commenced for test ${BOOT_ID}." | msmtp $RECIPIENT + +COUNTER=0 +FAILED_START=$(get_tx_failed) + +# Create CSV header if needed +if [ ! -f "$TEST_FILE" ]; then + echo "Link,Level,Noise,BSSID,TX Bitrate,RX Bitrate,$(speedtest --csv-header),TX Failures,Channel,Frequency,Packet Loss,Jitter" > "$TEST_FILE" +fi + +while [ "$COUNTER" -lt "$NUM_TESTS" ]; do + COUNTER=$((COUNTER + 1)) + echo "Executing test $COUNTER of $NUM_TESTS..." + + for ((i=1; i<=NUM_SAMPLES; i++)); do + echo " Gathering sample $i of $NUM_SAMPLES..." + + # Wireless stats + link_level_noise=$(awk 'NR==3 {gsub(/\./, "", $3); gsub(/\./, "", $4); gsub(/\./, "", $5); print $3","$4","$5}' /proc/net/wireless) + bssid_and_bitrate=$(iw dev wlan0 link | awk '/Connected/ {bssid=$3} /tx bitrate/ {tx=$3} /rx bitrate/ {rx=$3} END {print bssid","tx","rx}') + + # Speed test + speed_results=$(speedtest --secure --csv) + + # TX failure delta + FAILED_NOW=$(get_tx_failed) + FAILED_DELTA=$((FAILED_NOW - FAILED_START)) + FAILED_START=$FAILED_NOW # Update for next sample + + freq=$(iw dev wlan0 link | awk '/freq:/ {print $2}') + channel=$(freq_to_channel "$freq") + + packet_loss=$(ping -c $PING_COUNT -q $PING_TARGET | grep -oP '\d+(?=% packet loss)') + jitter=$(ping -c $PING_COUNT $PING_TARGET | grep "time=" | awk '{print $(NF-1)}' | sed 's/time=//g' | awk '{sum+=$1; sumsq+=$1*$1} END {if (NR>1) print sqrt(sumsq/NR - (sum/NR)**2); else print 0}') + + # Log everything + echo "$link_level_noise,$bssid_and_bitrate,$speed_results,$FAILED_DELTA,$channel,$freq,$packet_loss,$jitter" >> "$TEST_FILE" + done + + if [ "$COUNTER" -lt "$NUM_TESTS" ]; then + echo "Dozing off for $TIME_BETWEEN..." + sleep $TIME_BETWEEN + fi +done + +# Let's enrich the data with passive metrics. + +echo "Enriching the data..." + +python3 $SCRIPT_DIRECTORY/kismet_enrich_csv.py --csv $TEST_TILE --kismet "$KISMET_LOG" --output "$ENRICHED_FILE" + +# Final email with attachment +echo "The test with UID ${BOOT_ID} is complete. Please collect the probe. Data is attached." | \ +mutt -s "Test ${BOOT_ID} Complete" -a "$ENRICHED_FILE" -- "$RECIPIENT" +