Last active
January 24, 2025 19:21
-
-
Save bitmvr/43694379bdbeee1eba8860d630a92c4d to your computer and use it in GitHub Desktop.
Text Based Wi-Fi Analyzer for MacOS Terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
SLEEP_INTERVAL=5 | |
LOG_FILE="/tmp/wifi_monitor_$(date -u +%Y-%m-%d).json" | |
__get_wifi_info(){ | |
sudo wdutil info | egrep "(RSSI|Tx Rate|^\s*Channel\s*\:)" | |
} | |
__get_rssi(){ | |
data="$1" | |
echo "$data" | awk -F ':' 'NR==1{ print $2 }' | xargs | |
} | |
__get_tx_rate(){ | |
data="$1" | |
echo "$data" | awk -F ':' 'NR==2{ print $2 }' | xargs | |
} | |
__get_channel(){ | |
data="$1" | |
echo "$data" | awk -F ':' 'NR==3{ print $2 }' | xargs | |
} | |
while true; do | |
wifi_data="$(__get_wifi_info)" | |
rssi="$(__get_rssi "${wifi_data}")" | |
tx_rate="$(__get_tx_rate "${wifi_data}")" | |
channel="$(__get_channel "${wifi_data}")" | |
timestamp="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" | |
json_output="$(jq \ | |
--null-input \ | |
--compact-output \ | |
--arg timestamp "$timestamp" \ | |
--arg rssi "$rssi" \ | |
--arg tx_rate "$tx_rate" \ | |
--arg channel "$channel" \ | |
'{timestamp: $timestamp, rssi: $rssi, | |
tx_rate: $tx_rate, channel: $channel}' | |
)" | |
echo "$json_output" >> "$LOG_FILE" | |
sleep "$SLEEP_INTERVAL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment