mullvad-speedtest/speedtest.sh

24 lines
915 B
Bash
Executable file

#!/bin/bash
node_ids=$(mullvad relay list | grep -oE '[a-z]{2}-[a-z]{3}-\b(wg|ovpn)\b-[0-9]+')
IFS=$'\n' read -r -d '' -a node_ids_arr <<< "$node_ids"
set -e pipefail
results='{}'
for node in "${node_ids_arr[@]}"; do
mullvad relay set location "$node" >/dev/null
if ! mullvad connect --wait >/dev/null; then
echo "$node->WARN: failed to connect, skipping" >&2
continue
fi
echo "$node->INFO: connected to node"
test_output=$(librespeed-cli --no-icmp --json | jq '.[0]')
echo "$node->INFO: ping: $(jq '.ping' <<< $test_output)ms, jitter: $(jq '.jitter' <<< $test_output)ms, download: $(jq '.download' <<< $test_output)mbps, upload: $(jq '.upload' <<< $test_output)mbps"
results=$(jq --arg node "$node" --argjson test_output "$test_output" '. + {($node): $test_output}' <<< "$results")
mullvad disconnect --wait >/dev/null
echo "$results" > /tmp/mullvad-speedtest-results.json
done