Skip to content

Instantly share code, notes, and snippets.

@gmelodie
Last active May 26, 2023 19:04
Show Gist options
  • Save gmelodie/87d4121d5b9358952e47308e5b7f62b0 to your computer and use it in GitHub Desktop.
Save gmelodie/87d4121d5b9358952e47308e5b7f62b0 to your computer and use it in GitHub Desktop.
Turns wireless monitor mode on/off
if [ $# -ne 2 ]; then
echo "usage: ./monitor-mode.sh INTERFACE [on|off]"
exit 1
fi
# if interface not exists
sudo iw dev $1 info > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "unable to find device '$1'"
exit 2
fi
# if option is not on/off
if [ $2 != "on" ] && [ $2 != "off" ]; then
echo "expected either 'on' or 'off', got: '$2'"
exit 3
fi
sudo ip link set dev $1 down
if [ $2 = "on" ]; then
echo "Warning: this script stops NetworkManager"
sudo iwconfig $1 mode monitor
sudo service NetworkManager stop
elif [ $2 = "off" ]; then
sudo iwconfig $1 mode managed
sudo service NetworkManager start
fi
sudo ip link set dev $1 up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment