Skip to content

Instantly share code, notes, and snippets.

@mitchelhaan
Created June 19, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchelhaan/0e3d893d01793d0eebc29a78fdf6de95 to your computer and use it in GitHub Desktop.
Save mitchelhaan/0e3d893d01793d0eebc29a78fdf6de95 to your computer and use it in GitHub Desktop.
Run a loop of ping/interface status checks to help diagnose network issues
#!/bin/bash
logfile=~/Desktop/wifi_status.log
interval_sec=10
interface=en0
interface_info_cmd="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I"
# Combine stdout with stderr and pipe to a log file and the screen
exec > >(tee -a "$logfile") 2>&1
# Get a list of servers to ping at random, here we use the specified interface's DNS servers
ping_servers=($(scutil --dns | grep -B4 $interface | awk '/nameserver/ { print $NF }'))
#ping_servers=(8.8.8.8 8.8.4.4)
while [ 1 ]; do
ping_dest=${ping_servers[ $RANDOM % ${#ping_servers[@]} ]}
echo ""
date
echo "Ping $ping_dest: $(ping -b $interface -c 2 -o $ping_dest | grep icmp_seq)"
$interface_info_cmd
sleep $interval_sec
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment