speedtest-compare 803 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env bash
  2. #
  3. # This script will perform speedtests over wireguard and the
  4. # native connections and print their output
  5. #
  6. #
  7. _speedTestData() {
  8. local pingbps ping_f bps_f bps_int
  9. export ping_int mbps_int
  10. pingbps=$(speedtest-cli --no-upload --csv "$@" | cut -d"," -f7-8)
  11. ping_f="${pingbps%,*}" # grab first value
  12. ping_int="${ping_f%.*}" # make integer
  13. bps_f="${pingbps#*,}" # grab second value
  14. bps_int="${bps_f%.*}" # make integer
  15. mbps_int=$((bps_int / 1000000)) # convert to mbps
  16. }
  17. # Test Wireguard using automatic server selection
  18. if _speedTestData; then
  19. echo "Wireguard:"
  20. echo -e "\tPing: $ping_int"
  21. echo -e "\tMbps: $mbps_int"
  22. fi
  23. # Test native connection to ISP
  24. if _speedTestData --server 17170; then
  25. echo "Native:"
  26. echo -e "\tPing: $ping_int"
  27. echo -e "\tMbps: $mbps_int"
  28. fi