diff options
author | David Timber <dxdt@dev.snart.me> | 2024-11-13 02:16:08 +0100 |
---|---|---|
committer | David Timber <dxdt@dev.snart.me> | 2024-11-13 02:33:22 +0100 |
commit | c4618105a2c3f2d12b07efa7a0a27fa908d20eee (patch) | |
tree | c3286335ec027e44476673ab1440311d70b78951 /ping-he-tb | |
parent | b4a98534268fbab63f87f0eee0f826bb36dd97a2 (diff) |
Add and set up ping-he-tb
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" |