summaryrefslogtreecommitdiff
path: root/home
diff options
context:
space:
mode:
authorXiao Pan <gky44px1999@gmail.com>2023-02-18 19:52:59 -0800
committerXiao Pan <gky44px1999@gmail.com>2023-02-18 19:52:59 -0800
commitf2cf55d0406de0a370e5adbcf80b5d0f637c187c (patch)
tree96b57470863c5ab56d11194107eac0ca21e9bf5e /home
parent0b9d5ec563318e13315fd258434eb1210db2d6c2 (diff)
mrt, mullvad relay test if can reach specified website
Diffstat (limited to 'home')
-rwxr-xr-xhome/xyz/.local/bin/mrt34
1 files changed, 34 insertions, 0 deletions
diff --git a/home/xyz/.local/bin/mrt b/home/xyz/.local/bin/mrt
new file mode 100755
index 00000000..e99da9cd
--- /dev/null
+++ b/home/xyz/.local/bin/mrt
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Mullvad Relay Test
+
+location="Los Angeles"
+curl_maxtime=7
+website=www.baidu.com
+
+while getopts l:m:w: opt; do
+ case $opt in
+ l)location="$OPTARG";;
+ m)curl_maxtime="$OPTARG";;
+ w)website="$OPTARG";;
+ \?)exit 1;;
+ esac
+done
+
+mullvad relay update
+# info gawk Node: Ranges, 7.1.3 Specifying Record Ranges with Patterns
+# https://www.baeldung.com/linux/print-lines-between-two-patterns
+# https://stackoverflow.com/q/39384283/9008720
+for relay in $(mullvad relay list | awk -v location="$location" '
+$0 ~ location {f=1;next}
+/^\t[[:alpha:]]/ {f=0} f {
+ if($5 == "WireGuard,")
+ print $1
+}'); do
+ mullvad relay set hostname "$relay"
+ while ! mullvad status | grep -q "Connected to $relay"; do
+ sleep 0.1;
+ done
+ curl -Ism"$curl_maxtime" "$website" && good_relays="$good_relays $relay"
+done
+
+echo "$good_relays" | tee "$XDG_DOCUMENTS_DIR/logs/mrt_$(printf "$location" | tr '[:upper:] ' '[:lower:]_')_$website.log"