-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor
executable file
·64 lines (59 loc) · 1.29 KB
/
monitor
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
57
58
59
60
61
62
63
64
#!/bin/bash
case $# in
0) # 0 args, no interface, no command
IFACE="wifi0"
CMD=""
;;
1) # 1 arg: ambiguous
# 1 arg: interface, no command
if [[ $1 == wifi* ]] || [[ $1 == wlp* ]]; then
IFACE="$1"
CMD=""
# 1 arg: no interface, command
else
IFACE="wifi0"
CMD="$1"
fi
;;
2) # 2 args: interface, command
IFACE="$1"
CMD="$2"
;;
*) # wtf, bail
echo "Invalid arguments"
exit 1
;;
esac
# Bail if interface doesn't exist
if ! ip link show "$IFACE" > /dev/null; then
exit 1
fi
case $CMD in
"on")
sudo ip link set "$IFACE" down
sudo iw dev "$IFACE" set type monitor
sudo ip link set "$IFACE" up
;;
"off")
sudo ip link set "$IFACE" down
sudo iw dev "$IFACE" set type managed
sudo ip link set "$IFACE" up
;;
"up")
sudo ip link set "$IFACE" up
;;
"down")
sudo ip link set "$IFACE" down
;;
esac
echo -n "$IFACE: "
if ip link show "$IFACE" | grep 'UP' -q; then
echo -n "interface is up, "
else
echo -n "interface is down, "
fi
if ip link show "$IFACE" | grep 'radiotap' -q; then
echo "in monitor mode."
else
echo "not in monitor mode."
fi