Created
August 25, 2020 14:05
-
-
Save mikkorantalainen/3eb519670922c12ad2535d984d7cad3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Speedtest using speed.cloudflare.com servers | |
# Copyright 2020 Mikko Rantalainen <[email protected]> | |
# License: 2-clause BSD (https://opensource.org/licenses/BSD-2-Clause) | |
set -e | |
ID="$RANDOM$RANDOM$RANDOM" | |
BYTES="${BYTES:=1000000}" | |
SERVER="https://speed.cloudflare.com" | |
TEMPFILE="$(tempfile -p speed -s test)" | |
FORMAT="------------ Statistics: ------------ | |
TCP/IP handshake: %{time_connect} seconds | |
TLS handshake: %{time_appconnect} seconds | |
Time until request: %{time_pretransfer} seconds | |
Request size: %{size_request} bytes | |
Upload size: %{size_upload} bytes | |
Upload bandwidth: %{speed_upload} bytes/second | |
Download size: %{size_download} bytes | |
Download bandwidth: %{speed_download} bytes/second | |
HTTP status: %{http_code} | |
Total time: %{time_total} seconds | |
" | |
trap "rm -f -- '$TEMPFILE'" EXIT | |
echo | |
echo "Downloading zero bytes from $SERVER ..." | |
curl --progress-bar -o "$TEMPFILE" "$SERVER/__down?measId=$ID&bytes=0" -w "$FORMAT" | |
echo | |
# Store "__cfduid" cookie value | |
COOKIEVALUE="$(cat "$TEMPFILE")" | |
echo "Downloading $BYTES bytes from $SERVER ..." | |
curl --progress-bar -o "$TEMPFILE" "$SERVER/__down?measId=$ID&bytes=$BYTES" -w "$FORMAT" | |
echo | |
echo "Uploading $BYTES bytes to $SERVER ..." | |
curl --progress-bar -F upload=@"$TEMPFILE" -o /dev/null "$SERVER/__up?measId=$ID" -w "$FORMAT" | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example, to test 100 kB file transfers, run
if your shell. The script tests 1 MB file transfers by default. The maximum supported by Cloudflare servers seems to be 500 MB.