Skip to content

Instantly share code, notes, and snippets.

@apinstein
Last active June 1, 2020 11:07
Show Gist options
  • Save apinstein/c5b0f7b0f498caea4ed0 to your computer and use it in GitHub Desktop.
Save apinstein/c5b0f7b0f498caea4ed0 to your computer and use it in GitHub Desktop.
A simple shell script to test wifi connection over time and record data in a format for easy analysis.
#!/bin/zsh
# configure curl output format
echo '%{url_effective},%{time_namelookup},%{time_connect},%{time_appconnect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{time_total}' > curltime.format
# configure postgres
echo "create table wifi_data (ssid text,url_effective text,time_namelookup numeric(9,5),time_connect numeric(9,5),time_appconnect numeric(9,5),time_pretransfer numeric(9,5),time_redirect numeric(9,5),time_starttransfer numeric(9,5),time_total numeric(9,5));"
echo ""
echo "\\\\copy wifi_data from './wifi-data.csv' DELIMITER ',' CSV HEADER"
echo "select ssid, count(*), avg(time_total), stddev(time_total), min(time_total), max(time_total) from wifi_data group by ssid having count(*) > 5;"
echo ""
echo ""
# setup csv
echo 'ssid,url_effective,time_namelookup,time_connect,time_appconnect,time_pretransfer,time_redirect,time_starttransfer,time_total' > './wifi-data.csv'
while true; do
echo ` /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | pcregrep -o1 '\bSSID: *(.*) *'` \
, \
`curl -w "@curltime.format" --silent -o /dev/null http://www.google.com` \
| tee -a './wifi-data.csv'
sleep 1
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment