diff options
author | Xiao Pan <gky44px1999@gmail.com> | 2023-08-25 20:50:05 -0700 |
---|---|---|
committer | Xiao Pan <gky44px1999@gmail.com> | 2023-08-25 20:50:05 -0700 |
commit | d3b5dd46bb9077ba5c53db8620a225a66bb565fc (patch) | |
tree | c6ad95f91b3e4c93956078bef7a867c6a5c669d8 /sh/mrt | |
parent | fbf39b5e0b057272714a399fb5a4a59da84be993 (diff) |
update
Diffstat (limited to 'sh/mrt')
-rwxr-xr-x | sh/mrt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sh/mrt b/sh/mrt new file mode 100755 index 0000000..b39aeac --- /dev/null +++ b/sh/mrt @@ -0,0 +1,51 @@ +#!/bin/sh +# Mullvad Relay Test + +# Possible reasons for not reaching baidu.com and baomitu.com: +# https://github.com/mullvad/dns-blocklists/issues/86#issuecomment-1479102157 +# https://www.reddit.com/r/mullvadvpn/comments/10sht67/open_chinese_search_machines + +location="Los Angeles" +# about 2 to 3 seconds for fast connection, 5 to 7 seconds for slow connection, to specified website +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 +# https://stackoverflow.com/a/38972737/9008720 +# https://stackoverflow.com/a/17988834/9008720 +# https://unix.stackexchange.com/q/63891/459013 +# https://stackoverflow.com/a/17914105/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" + t=0 + while [ $t -lt 30 ]; do + if mullvad status | grep -q "Connected to $relay"; then + if curl -Ism"$curl_maxtime" "$website"; then + good_relays="$(printf '%s\n' "$good_relays" "$relay")" + fi + break + fi + sleep 0.1 + t=$((t+1)) + done +done + +echo "$good_relays" | tee "$XDG_DOCUMENTS_DIR/logs/mrt_$(printf '%s' "$location" | tr '[:upper:] ' '[:lower:]_')_$website.log" |