Skip to content

Instantly share code, notes, and snippets.

@mazurkin
Forked from mariusrugan/speedtest.sh
Created February 6, 2018 13:32
Show Gist options
  • Save mazurkin/d57b7c68198141c24e223e36cebd5685 to your computer and use it in GitHub Desktop.
Save mazurkin/d57b7c68198141c24e223e36cebd5685 to your computer and use it in GitHub Desktop.
CURL download benchmark
#!/ffp/bin/bash
SOURCES=(
"http://ns0.multikabel.net/100mb.nul"
"http://servermars.nl/100mb.bin"
"http://speedtest.tweak.nl/100mb.bin"
"http://cachefly.cachefly.net/100mb.test"
"http://mirror.leaseweb.com/speedtest/100mb.bin"
"http://mirror.de.leaseweb.net/speedtest/100mb.bin"
"http://178.238.129.83/bigtest.tgz"
"http://speedtest.wdc01.softlayer.com/downloads/test100.zip"
"http://testmeplease-eu.s3.amazonaws.com/100mb.bin"
"http://testmeplease-us.s3.amazonaws.com/100mb.bin"
)
for (( i = 0 ; i < ${#SOURCES[@]} ; i++ )) do
SOURCE=${SOURCES[$i]}
DOWNLOAD_RESULT=`curl -o /dev/null ${SOURCE} -w "%{speed_download}|%{size_download}|%{time_total}|%{time_namelookup}|%{time_connect}|%{time_pretransfer}|%{time_redirect}|%{time_starttransfer}|%{num_connects}\n" -s | sed 's/^|//; s/|$//; s/[ ]*|[ ]*/|/g;'`
oIFS="$IFS"; IFS=$'\n'
for line in $DOWNLOAD_RESULT; do
IFS='|'
arr=($line)
SPEED_mbit=`echo | awk '{ print "'"${arr[0]}"'"*0.000008 }'`;
SPEED_kbit=`echo | awk '{ print "'"${arr[0]}"'"*0.008 }'`;
COMPUTED_SPEED=`echo | awk '{ print ("'"${arr[1]}"'"/"'"${arr[2]}"'")*0.000008 }'`;
SOURCE_NAME=`basename $(dirname "${SOURCE}")`
SOURCE_IP=`ping -c 1 ${SOURCE_NAME} | grep -Eo -m 1 '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'`
IP_2_COUNTRY=`curl http://api.wipmania.com/${SOURCE_IP}?google.com -s`
echo `date +%d-%m-%Y/%H:%M/%Z` ${SOURCE} ${IP_2_COUNTRY} ${SOURCE_IP} $SPEED_mbit"/mbps" $SPEED_kbit"/kbps" ${arr[1]}"/bytes" "avg:"${COMPUTED_SPEED}"/mbit" >> ~/speedtest.txt
done
IFS="$oIFS"
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment