Skip to content

Instantly share code, notes, and snippets.

@TheCrazyGM
Created July 13, 2025 11:34
Show Gist options
  • Select an option

  • Save TheCrazyGM/52e6f57d75b864cbf7b5c56e7baaccd5 to your computer and use it in GitHub Desktop.

Select an option

Save TheCrazyGM/52e6f57d75b864cbf7b5c56e7baaccd5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if the argument is provided
if [ $# -eq 0 ]; then
echo "Please provide a filename as an argument."
exit 1
fi
# Read each line of the file
while read -r address; do
# setting timeout, piping error
# Execute ping; if it fails, skip to the next address
result=$(ping -c 1 -W 2 "$address" 2>/dev/null) || continue
# Extract the ping time from the result using cut
time=$(echo "$result" | grep "time=" | cut -d "=" -f 4)
# Print the address and the ping time
echo "$address $time"
done <"$1" | sort -k 2n | column -t -N "Address,Speed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment