scripts/i3-configuration/i3blocks/wifi_monitor.sh

28 lines
701 B
Bash
Raw Normal View History

#!/bin/bash
# Detect the active WiFi interface
wifi_interface=$(iw dev | awk '$1=="Interface"{print $2}')
# If no WiFi interface is found, exit
if [ -z "$wifi_interface" ]; then
2025-11-01 15:36:22 +01:00
echo " down"
exit 1
fi
# Get the WiFi details
2025-11-01 15:36:22 +01:00
wifi_info=$(iwconfig "$wifi_interface" 2> /dev/null)
# Extract the SSID and signal strength
ssid=$(echo "$wifi_info" | awk -F '"' '/ESSID/ {print $2}')
2025-11-01 15:36:22 +01:00
signal=$(echo "$wifi_info" | awk '/Signal level/ {print $4}' | sed 's/level=//')
2024-11-18 15:17:54 +01:00
# Get the IP address
2025-11-01 15:36:22 +01:00
ip_address=$(ip addr show "$wifi_interface" | awk '/inet / {print $2}' | cut -d/ -f1)
2024-11-18 15:17:54 +01:00
# Output the result
if [ -z "$ssid" ]; then
2025-11-01 15:36:22 +01:00
echo " down"
else
2025-11-01 15:36:22 +01:00
echo "$ssid ($signal dBm) $ip_address"
fi