diff options
Diffstat (limited to 'ping-he-tb')
-rwxr-xr-x | ping-he-tb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ping-he-tb b/ping-he-tb new file mode 100755 index 0000000..b87f8b2 --- /dev/null +++ b/ping-he-tb @@ -0,0 +1,45 @@ +#!/bin/bash +main () { + cd "$TMPDIR" + + set +e + LIST=$(curl -sSL 'https://tunnelbroker.net/status.php' | + grep -Eo 'title="[0-9.]+"' | + grep -Eo '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') + set -e + + for addr in $LIST + do + ping -qnc4 "$addr" > "$addr" & + done + + set +e # ignore non-zero exit code from ping command + for addr in $LIST + do + wait + done + set -e + + for addr in $LIST + do + avg=$(echo $(cat "$addr" | + grep -Eo 'rtt min/avg/max/mdev = [0-9.]+/[0-9.]+/[0-9.]+/[0-9.]+' | + grep -Eo '[0-9.]+') | + awk '{print $2}') + if [ -z "$avg" ]; then + avg="inf" + fi + + echo "$avg $addr" + done | sort -g +} + +set -e +TMPDIR=$(mktemp -d) +set +e + +main & wait +ec="$?" + +rm -rf "$TMPDIR" +exit "$ec" |