12345678910111213141516171819202122232425262728293031323334 |
- #!/usr/bin/env bash
- # This script performs speedtests over Wireguard and native connections and prints their output
- run_test() {
- local output pingBps pingPart bpsPart bpsInt
- # Run speedtest-cli and extract the 7th and 8th CSV fields
- output=$(speedtest-cli --no-upload --csv "$@" 2>/dev/null) || return 1
- pingBps=$(echo "$output" | cut -d"," -f7-8)
-
- # Extract ping value (as an integer) and bps (and convert to Mbps)
- pingPart="${pingBps%,*}"
- bpsPart="${pingBps#*,}"
- pingInt="${pingPart%.*}"
- bpsInt="${bpsPart%.*}"
- mbpsInt=$(( bpsInt / 1000000 ))
-
- echo "$pingInt $mbpsInt"
- }
- # Test Wireguard using automatic server selection
- if output=$(run_test); then
- read -r pingInt mbpsInt <<< "$output"
- echo "Wireguard:"
- echo -e "\tPing: $pingInt"
- echo -e "\tMbps: $mbpsInt"
- fi
- # Test native connection to ISP
- if output=$(run_test --server 17170); then
- read -r pingInt mbpsInt <<< "$output"
- echo "Native:"
- echo -e "\tPing: $pingInt"
- echo -e "\tMbps: $mbpsInt"
- fi
|