speedtest-compare 799 B

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