Created
June 19, 2017 18:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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