-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-iw.sh
56 lines (47 loc) · 2.04 KB
/
check-iw.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# MIT License (c) 2024 straysheep-dev
# check-iw.sh
# Tracks each interface's state and channel
# shellcheck disable=SC2034
# Colors and color printing code taken directly from:
# https://github.com/carlospolop/PEASS-ng/blob/master/linPEAS/builder/linpeas_parts/linpeas_base.sh
C=$(printf '\033')
DG="${C}[1;90m" #DarkGray
LM="${C}[1;95m" #LightMagenta
SED_RED="${C}[1;31m&${C}[0m"
SED_GREEN="${C}[1;32m&${C}[0m"
SED_YELLOW="${C}[1;33m&${C}[0m"
SED_RED_YELLOW="${C}[1;31;103m&${C}[0m"
SED_BLUE="${C}[1;34m&${C}[0m"
SED_LIGHT_MAGENTA="${C}[1;95m&${C}[0m"
SED_LIGHT_CYAN="${C}[1;96m&${C}[0m"
SED_BOLD="${C}[01;01m&${C}[0m"
NC="${C}[0m"
WIFACE="$1"
while true
do
clear
echo -e "${DG}╔═══════════════════════════════════════════════════════════════════${NC}"
echo -e "${DG}║ Viewing Wireless Interface Information${NC}"
echo -e "${DG}║ • This will run conitnuously with the latest interface information${NC}"
echo -e "${DG}║ • Run with ./check-iw.sh wlanX to list nearby Wi-Fi APs with wlanX${NC}"
echo -e "${DG}║ • Ctrl+c to quit${NC}"
echo -e "${DG}╚ Hostname: $(hostname) | ${NC}${LM}$(iw reg get | grep -A 1 '^global$' | grep 'country')${NC}${DG} | $(date +%F) $(date +%T)${NC}"
iw dev | grep -P "(Interface|type|channel)" | \
sed 's/Interface/\n[◢]/g' | sed -E 's/^\s+//g' | \
sed -E 's/^type/ ➤ Type/g' | \
sed -E 's/^channel/ ➤ Channel/g' | \
sed -E "s/.*mon$/${SED_YELLOW}/g" | \
sed -E "s/^.+Type monitor/${SED_YELLOW}/g" | \
sed -E "s/^.+wlan[0-9]+$/${SED_GREEN}/g" | \
sed -E "s/^.+Channel.+/${SED_LIGHT_CYAN}/g"
echo ""
if [[ "$1" != '' ]]; then
# https://unix.stackexchange.com/questions/356753/bash-always-outputs-to-less-how-can-i-turn-this-off
# https://manpages.debian.org/bookworm/network-manager/nmcli.1.en.html
# With `|| exit 1`, the script will exit if the interface can't be used
PAGER=''
sudo nmcli device wifi list ifname "$WIFACE" || exit 1
fi
sleep 1
done