From c45f58fd2080c2e96a5b2d933a70243a3698520e Mon Sep 17 00:00:00 2001 From: nervuri Date: Fri, 24 Sep 2021 12:18:34 +0000 Subject: [PATCH] test if removed hosts are still online --- get-hosts.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/get-hosts.sh b/get-hosts.sh index 1bd129f..0767bf7 100755 --- a/get-hosts.sh +++ b/get-hosts.sh @@ -68,6 +68,35 @@ if [ -z "$hosts" ]; then exit 1 fi +# Save to temporary file. +tempfile=$(mktemp) +echo "$hosts" > "$tempfile" + +# Delete temporary file on exit. +finish() { + rm -f "$tempfile" +} +trap finish EXIT + +# Test if removed hosts are still online. +echo "Testing removed hosts..." +for removed_host in $(diff hosts "$tempfile" | grep ^\< | cut -c 3-); do + printf "%s" "$removed_host" + # If direct connection fails, try to connect through Tor. + if agunua --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1 || \ + agunua --socks 127.0.0.1:9050 --no-tofu --maximum-time 20 "$removed_host" >/dev/null 2>&1; then + echo " - ONLINE" + # Add removed host back. + hosts="$hosts +$removed_host" + else + echo " - offilne" + fi +done + +# Sort entries again. +hosts=$(echo "$hosts" | sort) + # Save to file. echo "$hosts" > hosts