Skip to content

Commit

Permalink
Dynamically find wifi network interfaces for wifi_scan
Browse files Browse the repository at this point in the history
Enhance wifi scan troubleshooter to find all wifi capable devices on the fpp device and then get the AP's that each can see - this replaces a hardcode wlan0
  • Loading branch information
OnlineDynamic authored Oct 16, 2024
1 parent 0dcd5de commit 42099c3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions scripts/wifi_scan.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
#!/usr/bin/bash

iwlist wlan0 scanning > /tmp/wifiscan #save scan results to a temp file
scan_ok=$(grep "wlan" /tmp/wifiscan) #check if the scanning was ok with wlan0
if [ -z "$scan_ok" ]; then
iwlist wlan0-1 scanning > /tmp/wifiscan
fi
scan_ok=$(grep "wlan" /tmp/wifiscan) #check if the scanning was ok
#look for wifi device names on system
iw dev | awk '$1=="Interface"{print $2}' > /tmp/wifi_devices

cat /tmp/wifi_devices | while read wifi_device || [[ -n $wifi_device ]];
do

iwlist $wifi_device scanning > /tmp/wifiscan #save scan results to a temp file
scan_ok=$(grep "$wifi_device" /tmp/wifiscan) #check if the scanning was ok
if [ -z "$scan_ok" ]; then #if scan was not ok, finish the script
echo -n "
WIFI scanning failed.
"
exit
continue
fi

connected_address=$(iwconfig wlan0 | sed -n 's/.*Access Point: \([0-9\:A-F]\{17\}\).*/\1/p')
connected_address=$(iwconfig $wifi_device | sed -n 's/.*Access Point: \([0-9\:A-F]\{17\}\).*/\1/p')

if [ -f /tmp/ssids ]; then
rm /tmp/ssids
Expand All @@ -40,17 +42,17 @@ while [ "$i" -le "$n_results" ]; do
oneaddress=$(grep " Address:" /tmp/onecell | awk '{print $5}')
onessid=$(grep "ESSID:" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("ESSID:", "");print}')
# onechannel=$(grep " Channel:" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("Channel:", "");print}')
onefrequency=$(grep " Frequency:" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("Frequency:", "");print}')
onefrequency=$(grep " Frequency:" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("Frequency:", "");print}')
oneencryption=$(grep "Encryption key:" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("Encryption key:on", "(secure)");print}' | awk '{gsub("Encryption key:off", "(open) ");print}')
onepower=$(grep "Quality=" /tmp/onecell | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{gsub("Quality=", "");print}' | awk -F '/70' '{print $1}')
onepower=$(awk -v v3=$onepower 'BEGIN{ print v3 * 10 / 7}')
onepower=${onepower%.*}
onepower="(Signal strength: $onepower%)"
if [ "$connected_address" == "$oneaddress" ]; then
if [ "$connected_address" == "$oneaddress" ]; then
currentcon=" - Connected"
else
else
currentcon=""
fi
fi
if [ -n "$oneaddress" ]; then
echo "$onessid $onefrequency $oneaddress $oneencryption $onepower $currentcon" >> /tmp/ssids
else
Expand All @@ -61,10 +63,14 @@ done
rm /tmp/onecell
awk '{printf("%5d : %s\n", NR,$0)}' /tmp/ssids > /tmp/sec_ssids #add numbers at beginning of line
grep ESSID /tmp/wifiscan | awk '{ sub(/^[ \t]+/, ""); print }' | awk '{printf("%5d : %s\n", NR,$0)}' | awk '{gsub("ESSID:", "");print}' > /tmp/ssids #generate file with only numbers and names
printf "Wifi Device: $wifi_device\n"
echo -n "Available WIFI Access Points:
"
cat /tmp/sec_ssids #show ssids list
printf "\n"

rm /tmp/ssids
rm /tmp/sec_ssids
rm /tmp/wifiscan
done
rm /tmp/wifi_devices

0 comments on commit 42099c3

Please sign in to comment.