Skip to content

Instantly share code, notes, and snippets.

@donalod
Last active August 29, 2015 14:06
Show Gist options
  • Save donalod/ba467ffdb2a2531cd13e to your computer and use it in GitHub Desktop.
Save donalod/ba467ffdb2a2531cd13e to your computer and use it in GitHub Desktop.
WiFi Debugging on OSX
#!/usr/bin/env bash
# Remember to change the "Podomere" SSID to name grab your preferred/connected SSIDs
# Also update the default gateway!
# Change to a SpeedTest server near you from http://www.speedtest.net/speedtest-servers.php
# Pick a small file http://lowendtalk.com/discussion/2178/speed-test-files-1-300-locations
# And run this file from a wifitest directory and put it in your crontab for every minute!
# Note: add your BSSID,APname in to a file called "bssidsapnames.txt" in the same directory!!
# Yes this is a quick and nasty script! All improvements welcome including shortening :)
# To simply call airport commands you can sym link the Apple OSX airport binary to somewhere
# in your existing path e.g.
# "sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport \\
# /usr/sbin/airport"
# Note: On OSX you can use "system_profiler -listDataTypes" to get fun info!
# Also PLEASE NOTE that this generated data then becomes very easily parsed with standard unix tools e.g
# to get SNR you can just do this... or indeed another simple grep/egrep for 'noise' etc.
# egrep -hi signal /Volumes/dat1/wifitest/debugging/wifitest_2014-09-27* | awk '{sum = $5 - $8; print $1" " $5" " $8" SNR:" sum}'
# Please amend any file or user paths for your own system and then place the script in cron for every minute and you will
# have continual performance monitoring which you can easily graph or ask questions of with basic ubiquitous tools.
# See some of the other gists above to simply graph or alert on conditions...
now=$(date +%Y-%m-%d_%H.%M.%S)
file="/Users/Account/wifitest/wifitest_$now.txt"
touch "$file"
if [ ! -f "/Users/Account/wifitest/bssidsapnames.txt" ]; then
touch "/Users/Account/wifitest/bssidsapnames.txt"
fi
function stamp {
sed -e "s/^/$(date +%Y-%m-%d_%H.%M.%S) /" | tee -a "$file"
}
echo "======NewFile======" | stamp
for i in {1..5}
do
echo "======Begin=======" | stamp
/usr/sbin/system_profiler SPAirPortDataType | egrep -i "Status:|PHY Mode:|en:|Channel:|Country|Signal|Rate:|Index:" | sed 's/^[ \t]*//;s/[ \t]*$//' | stamp
bssid=`/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | egrep -i "BSSID" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{print $2}'`
#bssid=`/usr/sbin/system_profiler SPAirPortDataType | egrep -i "BSSID" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{print $2}'`
/usr/sbin/airport -I | egrep -i " SSID:|maxRate:" | sed 's/^[ \t]*//;s/[ \t]*$//' | stamp
#echo "BSSID: $bssid" | stamp
echo "$bssid" | awk 'FNR==NR{a[$1]=$2;next}{print "Access Point Name: " a[$1]}' FS=',|;' OFS=',' /Users/Account/wifitest/bssidsapnames.txt - | stamp
/usr/sbin/system_profiler SPPowerDataType | egrep -i "Charging:|Amperage|Voltage|Connected|Wattage" | sed 's/^[ \t]*//;s/[ \t]*$//' | stamp
/usr/sbin/ioreg -w 0 -l | egrep -i "\"voltage|cellvoltage" | sed 's/|//g;s/^[ \t]*//;s/[ \t]*$//' | stamp
echo "======Router_ICMP_Ping======" | stamp
/sbin/ping -A -c3 -i1 -t3 10.1.1.1 | tail -n2 | stamp
echo "======Google_ICMP_Ping======" | stamp
/sbin/ping -A -c3 -i1 -t3 google.com | tail -n2 | stamp
echo "======Google_Homepage=======" | stamp
curl -L -s -o /dev/null -w 'DNSLookup:%{time_namelookup}ms Total:%{time_total}ms Speed:%{speed_download} Bytes p/s(times 8 for bps) Data:%{size_download} Bytes' http://google.com/ | stamp
done
echo "====TelstraSpeedTestFile===" | stamp
curl -L -s -o /dev/null -w 'DNSLookup:%{time_namelookup}ms Total:%{time_total}ms Speed:%{speed_download} Bytes p/s(times 8 for bps) Data:%{size_download} Bytes' http://per1.speedtest.telstra.net/speedtest/random350x350.jpg | stamp
echo "==== LOCAL SCAN ===========" | stamp
/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -s | sort -k3 | sed -e "s/^/$(date +%Y-%m-%d_%H.%M.%S) Scan~/" | tee -a "$file"
echo "=====EndFile======" | stamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment