speedtest-compare 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. # This script performs speedtests over Wireguard and native connections and prints their output
  3. run_test() {
  4. local output pingBps pingPart bpsPart bpsInt
  5. # Run speedtest-cli and extract the 7th and 8th CSV fields
  6. output=$(speedtest-cli --no-upload --csv "$@" 2>/dev/null) || return 1
  7. pingBps=$(echo "$output" | cut -d"," -f7-8)
  8. # Extract ping value (as an integer) and bps (and convert to Mbps)
  9. pingPart="${pingBps%,*}"
  10. bpsPart="${pingBps#*,}"
  11. pingInt="${pingPart%.*}"
  12. bpsInt="${bpsPart%.*}"
  13. mbpsInt=$(( bpsInt / 1000000 ))
  14. echo "$pingInt $mbpsInt"
  15. }
  16. # Test Wireguard using automatic server selection
  17. if output=$(run_test); then
  18. read -r pingInt mbpsInt <<< "$output"
  19. echo "Wireguard:"
  20. echo -e "\tPing: $pingInt"
  21. echo -e "\tMbps: $mbpsInt"
  22. fi
  23. # Test native connection to ISP
  24. if output=$(run_test --server 17170); then
  25. read -r pingInt mbpsInt <<< "$output"
  26. echo "Native:"
  27. echo -e "\tPing: $pingInt"
  28. echo -e "\tMbps: $mbpsInt"
  29. fi