Skip to content

Instantly share code, notes, and snippets.

@nexus166
Last active October 9, 2019 22:29
Show Gist options
  • Select an option

  • Save nexus166/160229a9aca567ce1dd9c96b0bfddbe9 to your computer and use it in GitHub Desktop.

Select an option

Save nexus166/160229a9aca567ce1dd9c96b0bfddbe9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -eo pipefail
TARGETs=(${@})
avg_lat() { basename $(ping -s 4096 -c 10 -q "${1}" | awk '/avg/ {print $4}'); }
w8() { c=0; for p in ${@}; do (wait ${p} 2>/dev/null || c=$?) & done; wait; }
work() { echo -e "$(avg_lat ${1})\\t${1}\\t$(curl -s ipinfo.io/${1} | jq -r '.loc,.country,.region' | tr '\n' '\t')"; }
pids=()
echo -e "RTT\\tADDR\\t\\tLOC\\t\\tCOUNTRY\\tREGION"
for _ip in ${TARGETs[@]}; do
pids+=($!);
work "${_ip}" &
done | sort -V & w8 ${pids[@]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment