Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active December 25, 2015 12:49
Show Gist options
  • Select an option

  • Save timabell/6978970 to your computer and use it in GitHub Desktop.

Select an option

Save timabell/6978970 to your computer and use it in GitHub Desktop.
Tools for troubleshooting wireless problems. * log access point in use * monitor access point changes * scan and test all access points
sudo watch -d -n 10 'wpa_cli -i wlan0 status | sed -n "s/.*bssid=\(.*\).*/\1/gp"'
#!/bin/bash
ap=$1
echo Connecting to $ap ...
sudo wpa_cli -i wlan0 bssid 0 $ap > /dev/null
sudo wpa_cli -i wlan0 reassociate > /dev/null
sleep 4
STATUS=`sudo wpa_cli -i wlan0 status`
CONNECTED_TO=`echo "$STATUS" | sed -n "s/.*bssid=\(.*\).*/\1/gp"`
if [[ "$ap" == "$CONNECTED_TO" ]]; then
echo "Connected"
else
echo "Failed to connect to $ap"
fi
echo
#!/bin/sh
MAC=`sudo iwconfig wlan0 | sed -n 's/.*Access Point: \(.*\)$/\1/gp'`
echo $MAC $1 `date` >> hitlist.txt
echo $MAC $1
#!/bin/sh
egrep '(bssid|loss|rtt)' $1 | awk 'BEGIN {print "bssid\tpacket_loss\tavg_ping_ms"} {print $0}'
#!/bin/bash
echo Generated by https://gist.github.com/timabell/6978970
# bash not sh to get case insensitive compare for mac http://stackoverflow.com/a/1728814/10245
shopt -s nocasematch
SSID=`sudo iwconfig wlan0 | sed -n 's/.*ESSID:"\(.*\)".*/\1/gp'`
echo Checking access points for ssid $SSID ...
echo -n
AP_LIST=`sudo iwlist wlan0 scan essid $SSID | awk '{ if ($0 ~ /Cell/) {printf $5} else if ($0 ~ /Quality/) {print} }' | sort`
echo "$AP_LIST"
echo
APS_BY_STRENGTH=`echo "$AP_LIST" | awk '{print $4 " " $5 " " $1}' | sort -n`
echo "Ordered by strength:"
echo "$APS_BY_STRENGTH"
MAC_LIST=`echo "$APS_BY_STRENGTH" | awk '{print $3}'`
echo
for ap in $MAC_LIST
do
echo Connecting to $ap ...
sudo wpa_cli -i wlan0 bssid 0 $ap > /dev/null
sudo wpa_cli -i wlan0 reassociate > /dev/null
sleep 4
STATUS=`sudo wpa_cli -i wlan0 status`
CONNECTED_TO=`echo "$STATUS" | sed -n "s/.*bssid=\(.*\).*/\1/gp"`
if [[ "$ap" == "$CONNECTED_TO" ]]; then
ping -c 30 -i 0.2 -s 1024 ic.ac.uk | egrep 'loss|rtt'
else
echo "Failed to connect to $ap"
fi
echo
done
echo done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment