Write a bash script to scan wi-fi interface, output values with the following fields and saves the results to a file. The script should continuously output the values unless a keyboard interrupt is...

1 answer below »

Write a bash script to scan wi-fi interface, output values with the following fields and saves the results to a file. The script should continuously output the values unless a keyboard interrupt is invoked.


·Bit Rate (Mb/s)


·Tx-Power(dBm)


·RSSI


·Signal(dBM)


·Noise-

Answered Same DayOct 20, 2021

Answer To: Write a bash script to scan wi-fi interface, output values with the following fields and saves the...

Sandeep Kumar answered on Oct 21 2021
152 Votes
#!/bin/sh
#
#Filename: wifi-strength.sh
#Description: This script scans for "masters" and displays wifi signal strength
# Script Dependency: B{ASH} like shell and iw. No other package requirements.
#
# The SSID and signal strength are from iw output, others are
# calcu
lated like Quality and GOOD/BAD signal.
#
# As root:
# sh wifi-strength.sh -h
#
# As normal user:
# sudo bash wifi-strength.sh -h
#
# Set Defaults
strenght_str='#' # default pound sign
bar_len='50' # default 50
bar_fill_char=' ' # default space
sort_data=0 # sort scan results best signal to worst
num_lines=''
#must provide the network interface, wlan0 for example
if [ $# -lt 1 ]; then
# shellcheck disable=SC2039
echo -ne "
Usage: \"$(basename -- "$0") [options] [interface]\"
-- for example;
\t$(basename -- "$0") wlan1\t# scan wlan1
\t$(basename -- "$0") -h\t# for help
\n Interfaces found:
"
iw dev 2>/dev/null | grep "Interface" | awk '{print $2}'
exit
fi
# Parse command line options and ignore invalid.
parse_options() {
for arg in "$@"; do
case "$arg" in
-h)
usage_txt
;;
-m)
scan=0
shift
;;
-n)
num_lines="$2"
shift
;;
-f)
force=1
shift
;;
-s)
sort_data=1
shift
;;
-l)
if [ "$(echo "$2" | grep -E '^[1-9][0-9]?$|^100$')" ]; then bar_len="$2"; fi
shift
;;
*)
shift
;;
esac
#Last arg is the network interface, required.
net=$arg
done
}
# Help text
usage_txt() {
script=$(basename -- "$0")
echo -ne "
Usage: $script [options]
The interface to monitor.
[options]
-m\tMonitor link signal strength.
-s\tSort scan results.
-n\tDisplay x number of lines
-f\tForce monitoring even if interface does not exist.
-l\tLength of strength bar, range 1-100, Default 50
Example:
Scan for \"masters\" on interface wlan1;
\t$script wlan1
Scan for \"masters\" on wlan1 set strength bar length to 80
and sort SSID's strongest to weakest signal;
\t$script -l 80 -s wlan1
Monitor with bar graph on interface wlan1
\t$script -l 75 -m wlan1
\nInterfaces found:
"
iw dev 2>/dev/null | grep "Interface" | awk '{print $2}'
echo -ne "\n\n"
exit
}
# Create $len length signal bar from percentage of $quality.
get_strength_bar() {
char=$1
fill_char=$bar_fill_char
num=$2
len=$3
# Calculate number of char(s) for strength part of bar
num_char=$(awk "BEGIN {printf \"%.0f\", $num/100*$len}")
# Calculate number of char(s) to fill the remaining part of the bar.
num_fill=$((len - num_char))
v=$(printf "%${num_char}s" "")
s=$(printf "%${num_fill}s"...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here