Skip to content

Instantly share code, notes, and snippets.

@hit0ri
Last active August 8, 2018 14:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hit0ri/aec2a34d31f6b9f58d8460fb12869450 to your computer and use it in GitHub Desktop.
Save hit0ri/aec2a34d31f6b9f58d8460fb12869450 to your computer and use it in GitHub Desktop.
Wi-Fi channel hopper
#!/bin/bash
msg() {
printf -- '%s\n' "$@"
}
err() {
printf -- 'error: %s\n' "$@" >&2
exit 1
}
usage() {
cat <<EOF
usage: ${0##*/} -i <wireless interface> [-v] [-h]
options
-i specify wireless interface name
-v enable verbose mode
-h show help
EOF
}
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
if [[ $EUID -ne 0 ]]; then
err 'insufficient permisions'
fi
if ! command -v iwlist &> /dev/null; then
err "iwlist: command not found"
fi
while getopts :i:vh arg; do
case $arg in
i) interface=$OPTARG ;;
v) verbose=1 ;;
h) usage; exit ;;
*) usage; exit 1 ;;
esac
done
# Get list of supported channels
channels=$(iwlist "$interface" freq | awk '/ Channel/ {printf "%s ", $2}')
if [[ $channels ]]; then
[[ $verbose ]] && msg "supported channels on $interface: $channels"
while :; do
for chan in $channels; do
iwconfig "$interface" channel "$chan" || err "$interface: error while hopping to channel $chan"
[[ $verbose ]] && msg "current channel on $interface: $chan"
sleep .10
done
done
else
err "$interface: failed to get supported channels"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment