LINUX - CLI Internet Connection Speed Tests

[update 7/29/2013]


speedtest-cli new install script as the git repo changed for it alittle, also a little cool script to test local server and a few other servers and output results to screen and file.


HOW TO INSTALL SIMPLE WAY

sudo apt-get install git-core


cd ~

git clone https://github.com/sivel/speedtest-cli.git


The difference is that its not as deep nested now

cd speedtest-cli

Now to run script

./speedtest-cli


Now you are done, if you want to make this program permanent so its not sitting in your home folder. The best option is to move it to one of your PATH variablaes (linux constantly checks those when you type any command in to see if its there)


echo $PATH


I see that /usr/local/bin is one of my paths


cp ~/speedtest-cli/speedtest-cli /usr/local/bin


I dont need to chmod +x as this file already has all the right permissions


Now from any directory running speedtest-cli will do a test


Confirm it works:


cd /

speedtest-cli


After you confirm it works delete the download directory

cd ~

rm -rf speedtest-cli


Okay now here is some usage


speedtest-cli --list

lists all of the ten billion million servers

test with anyone like this

speedtest-cli --server SERVERNUMBER

like to test with Optimum Online server in New York, NY USA

speedtest-cli --server 663


To get a picture of your results to share with the speedtest network or your friends/family/coworkers

speedtest --share

or

speedtest --server 663 --share

or instead of 663 any other valid server number


Next here is my script to list with a few servers plus the closest one to you (remember when not specifying a server it picks the closest one based on ping)


Get a list of servers like this

speedtest-cli --list | egrep -i "colorado|new york|britain|india|china|washington"


So then pick a few servers from the million numbers that outputs.


I picked 3864 2065 663 2789 2362 3047 1337 251 3927 2195 that kinda spans the world enough for me


So here is the awesome command, just type it out in notepad and then copy it out and paste it into your shell:


(echo "=====TESTING WITH: CLOSEST SERVER======"; speedtest-cli --share | egrep "load:|Hosted by|results"; for i in 3864 2065 663 2789 2362 3047 1337 251 3927 2195; do echo "======TESTING WITH: $i======="; speedtest-cli --share --server $i | egrep "load:|Hosted by|results"; done;) | tee ~/speedtests-`hostname`


Hopefully that doesnt have typos, I had to write it out, my googlesites kept crashing when I was trying to paste this in, and I am too lazy to fix it tommorow or do this tommorow so I am doing this now and had to type it out by hand...


Anyhow below is the old article there are a few other cool methods, this is just a rerendition of METHOD4 updated for how it is now, it might be different by the time you get to it.


Finally if you get any errors make sure you have the latest python requirements and google "speedtest-cli linux requirements"




LINUX - TEST INTERNET CONNECTION - SPEED TEST - INTERNET SPEED TEST

===================================================================


METHOD1: wget

METHOD2: lftp

METHOD3: iperf

METHOD4: speedtest-cli

METHOD5: script that runs wgets


METHOD 1a

##########


wget –O /dev/null http://ipv4.download.thinkbroadband.com/1GB.zip


another way just saves 9 keystrokes or so


wget –O /dev/null ipv4.download.thinkbroadband.com/1GB.zip


Then control C when you see the speed


METHOD 1b

###########


wget -O /dev/null http://hostve.com/neobuntu/pics/Ubu1.avi 

wget --output-document=/dev/null http://speedtest.wdc01.softlayer.com/downloads/test500.zip


METHOD 2

##########


sudo apt-get install lftp


DOWNLOAD:

lftp -e 'pget http://mirror.anl.gov/pub/centos/6.3/isos/x86_64/CentOS-6.3-x86_64-LiveCD.iso; exit; '

lftp -e 'pget http://hostve.com/neobuntu/pics/Ubu1.avi ; exit; '

lftp -e 'pget http://speedtest.example.com/500M.bin; exit; '

lftp -e 'pget http://speedtest.wdc01.softlayer.com/downloads/test500.zip; exit; '


UPLOAD:

lftp -u userName ftp.example.com -e 'put largecd1.avi; bye'

lftp -u userName,passWord ftp.example.com -e 'put largecd1.avi; bye'

lftp -u userName,passWord ftp.example.com -e 'put /path/to/large.iso; bye'


METHOD 2 - Good for local tests too

##########


ON SERVER & CLIENT: apt-get install iperf


BASIC IDEA:

SERVER: "iperf -s" or "iperf -s -p PORT"

CLIENT: "iperf -c SERVERIP" or "iperf -c SERVERIP -p PORT"


SERVER HAS A PUBLIC IP:

-B on server is optional it binds to specific interface, in this case the WAN IP is on the SERVER

ON SERVER:

# iperf -s -B 202.54.1.1

ON CLIENT:

# iperf -c 202.54.1.1 -d -t 60 -i 10


SERVER BEHIND PUBLIC IP / GOOD WITH LOCAL TESTS JUST CHANGE IPS:

WITH PORT 44444 PORT FORWARDED @ SERVER NETWORK TO SERVER:

ON SERVER:

# iperf -s -p 55555

ON CLIENT:

# iperf -c 202.54.1.1 -p 55555 -d -t 60 -i 10


IPERF OPTIONS FROM http://doc.pfsense.org/index.php/Iperf_man_page:

GENERAL OPTIONS

      -f, --format == [kmKM]   format to report: Kbits, Mbits, KBytes, MBytes

      -h, --help == print a help synopsis

      -i, --interval n == pause n seconds between periodic bandwidth reports

      -l, --len n[KM] == set length read/write buffer to n (default 8 KB)

      -m, --print_mss == print TCP maximum segment size (MTU - TCP/IP header)

      -o, --output <filename> == output the report or error message to this specified file

      -p, --port n == set server port to listen on/connect to to n (default 5001)

      -u, --udp == use UDP rather than TCP

      -w, --window n[KM] == TCP window size (socket buffer size)

      -B, --bind <host> == bind to <host>, an interface or multicast address

      -C, --compatibility == for use with older versions does not sent extra msgs

      -M, --mss n == set TCP maximum segment size (MTU - 40 bytes)

      -N, --nodelay == set TCP no delay, disabling Nagle's Algorithm

      -v, --version == print version information and quit

      -V, --IPv6Version == Set the domain to IPv6

      -x, --reportexclude == [CDMSV]   exclude C(connection) D(data) M(multicast) S(settings) V(server) reports

      -y, --reportstyle C|c == if set to C or c report results as CSV (comma separated values)

SERVER SPECIFIC OPTIONS

      -s, --server == run in server mode

      -U, --single_udp == run in single threaded UDP mode

      -D, --daemon == run the server as a daemon

CLIENT SPECIFIC OPTIONS

      -b, --bandwidth n[KM] == set  target  bandwidth to n bits/sec (default 1 Mbit/sec).  Thissetting requires UDP (-u).

      -c, --client <host> == run in client mode, connecting to <host>

      -d, --dualtest == Do a bidirectional test simultaneously

      -n, --num n[KM] == number of bytes to transmit (instead of -t)

      -r, --tradeoff == Do a bidirectional test individually

      -t, --time n == time in seconds to transmit for (default 10 secs)

      -F, --fileinput <name> == input the data to be transmitted from a file

      -I, --stdin == input the data to be transmitted from stdin

      -L, --listenport n == port to recieve bidirectional tests back on

      -P, --parallel n == number of parallel client threads to run

      -T, --ttl n == time-to-live, for multicast (default 1)

      -Z, --linux-congestion <algo> == set TCP congestion control algorithm (Linux only)


METHOD 3

##########


Install Git

=============

$ sudo apt-get install git-core


Clone the Repository from GitHub

==================================

$ git clone https://github.com/sivel/speedtest-cli.git


Sample Usage and Output

==========================

$ ./speedtest-cli


OUTPUT EXAMPLE

Retrieving speedtest.net configuration...

Retrieving speedtest.net server list...

Testing from Comcast Cable (x.x.x.x)...

Selecting best server based on ping...

Hosted by FiberCloud, Inc (Seattle, WA) [12.03 km]: 44.028 ms

Testing download speed........................................

Download: 32.29 Mbit/s

Testing upload speed..................................................

Upload: 5.18 Mbit/s


ALTERNATE METHOD TO INSTALL AND RUN speedtest-cli

====================================================


INSTALLING:

cd ~

git clone https://github.com/sivel/speedtest-cli.git

AND COPY SPEEDTEST-CLI RIGHT INTO ONE OF THE PATHS

echo $PATH

sudo cp ~/repo/remote/speedtest-cli/speedtest-cli SOMEPATH

OR JUST COPY IT TO BE AVAILABLE TO ALL USERS (YOU CAN ALSO PUT IT IN /SBIN/ OR /BIN.. /USR/LOCAL/BIN WORKS FINE TOO - AS LONG AS YOU SEE THAT IN YOUR PATH, IF /USR/LOCAL/BIN IS NOT IN YOUR PATH USE /BIN OR /SBIN)

sudo cp ~/repo/remote/speedtest-cli/speedtest-cli /usr/local/bin

 

RUNNING:


speedtest-cli --list

speedtest-cli --server 2965 --share

 

RUNNING WITH ARRAYS:


First check the servers:

$ speedtest-cli --list | grep -iE 'chicago|london|tokyo'

 

We are good to go, so let's move on to creating the associative array and implementing a for loop for iteration. Run the following commands:


$ declare -A servers=( [2574]="Chicago" [2789]="London" [251]="Tokyo" )

$ for server in ${!servers[@]}; do echo "Location: ${servers[$server]}"; speedtest-cli --server $server --simple; echo; done


OUTPUT EXAMPLE:

Location: Tokyo

Ping: 73.989 ms

Download: 31.37 Mbit/s

Upload: 3.93 Mbit/s


Location: London

Ping: 67.631 ms

Download: 68.65 Mbit/s

Upload: 22.39 Mbit/s


Location: Chicago

Ping: 64.055 ms

Download: 39.73 Mbit/s

Upload: 60.35 Mbit/s


METHOD 4

##########


WRITE THIS SCRIPT: netspeed.sh


#!/usr/bin/env bash

#              bash 4.1.5(1)     Linux Ubuntu 10.04               Date : 2011-10-09

#

# _______________|  netspeed : check download speed via command line.

#

#           Usage:  netspeed [tokyo, london, usw, use, east, west, URL]

#                                            ^default U.S. west coast.

#                            [ -speed_KB/sec ]

#                              ^negation activates the Mbps converter.

#

#                            First try it out without any arguments.

#                                            

#    Dependencies:  wget 

#                   (rate displayed in Kilobytes per second, 

#                    whereas speed tests usually adopt Megabits.)

#

#   Example units:  Download Speed: 659 kbps     (82.4 KB/sec transfer rate)

#                     Upload Speed: 317 kbps     (39.6 KB/sec transfer rate)

#                                       kb=kilobits    KB=Kilobytes

#                   So  0.007813 Mb =    8 kilobits =   1 Kilobyte

#                   since      1 Mb = 1024 kilobits = 128 Kilobytes

#

#           Units:  b stands for bit and B stands for byte. In the context of 

#                   data rate units, one byte refers to 8 bits. For example, 

#                   when a 1 Mbps connection is advertised, it usually means 

#                   that the maximum achievable download bandwidth is 

#                   1  megabit/s (million bits per second), which is actually 

#                   0.125   MB/s (megabyte per second), or about 

#                   0.1192 MiB/s (mebibyte per second). 

#                   http://en.wikipedia.org/wiki/Mbit/s#megabit_per_second

 

 

#  CHANGE LOG  get LATEST version from https://bitbucket.org/rsvp/gists/src

#

#  2011-10-09  Add rate conversion to Mbps using negated first argument.

#  2011-10-08  Add URL as possible arg. Clarify rate units.

#                 Public as gist to https://gist.github.com/1272488

#  2011-10-07  First version based on wget, though curl also works:

#                 http://stackoverflow.com/questions/426272

#                 Command line alternative to http://www.speedtest.net

 

#           _____ Prelims

set -u

#   ^ unbound (i.e. unassigned) variables shall be errors.

set -e

#   ^ error checking :: Highly Recommended (caveat:  you can't check $? later).  

#

# _______________     ::  BEGIN  Script ::::::::::::::::::::::::::::::::::::::::

 

site=${1:-'usw'}

 

 

case $site in 

     'london') test='http://london1.linode.com/100MB-london.bin'    ;;

     'tokyo')  test='http://tokyo1.linode.com/100MB-tokyo.bin'      ;;

     'usw')    test='http://fremont1.linode.com/100MB-fremont.bin'  ;;

               #  US West:  Fremont, California

     'use')    test='http://newark1.linode.com/100MB-newark.bin'    ;;

               #  US East:  Newark, New Jersey

     'east')   test='http://speedtest.wdc01.softlayer.com/downloads/test500.zip'                 ;;

               #  US East:  Washington, D.C.

     'west')   test='http://speedtest.sjc01.softlayer.com/speedtest/speedtest/random500x500.jpg' ;;

               #  US West:  San Jose, California

     *)        test=$1  ;;

               #  valid URL assumed, else wget will give any error message.

esac

     #  Sources:

     #  2011-10-07  http://www.linode.com/speedtest/      for file URL.

     #              http://speedtest.wdc01.softlayer.com  for actual testing.

 

 

 

if [ $test = -${test#-} ] ; then

     #     ^check for negative sign in the first argument.

     echo "`awk "END { print ($test * -0.007813) }" /dev/null` Mbps"

     #      awk as nice floating-point calculator!

else

     echo ' ::  Rate in Kilobytes/sec; industry usually adopts megabits/sec:       '

     echo ' ::        1 Kilobytes/sec (K/s)   =       0.007813 megabits/sec (Mbps).'

     echo ' ::        To convert, use negated rate as first argument to netspeed.  '

     echo ' ::  [Terminate netspeed by control-C]     [ cf. http://speedtest.net ] '

     echo ' ::  '

     #      MAIN

     wget  --output-document=/dev/null  $test 

fi

 

#       If --output-file for wget was used to log results...

#

#  --2011-10-07 21:38:27--  

#  Resolving speedtest.sjc01.softlayer.com... 50.23.64.58

#  Connecting to speedtest.sjc01.softlayer.com|50.23.64.58|:80... connected.

#  HTTP request sent, awaiting response... 200 OK

#  Length: 505544 (494K) [image/jpeg]

#  Saving to: `/dev/null'

#  

#       0K .......... .......... .......... .......... .......... 10% 80.9K 5s

#      50K .......... .......... .......... .......... .......... 20% 78.5K 5s

#     100K .......... .......... .......... .......... .......... 30% 80.8K 4s

#     150K .......... .......... .......... .......... .......... 40% 78.8K 4s

#     200K .......... .......... .......... .......... .......... 50% 80.8K 3s

#     250K .......... .......... .......... .......... .......... 60% 78.5K 2s

#     300K .......... .......... .......... .......... .......... 70% 78.8K 2s

#     350K .......... .......... .......... .......... .......... 81% 80.8K 1s

#     400K .......... .......... .......... .......... .......... 91% 78.5K 1s

#     450K .......... .......... .......... .......... ...       100% 81.9K=6.2s

#  

#  2011-10-07 21:38:33 (79.8 KB/s) - `/dev/null' saved [505544/505544]

 

 

exit 0

# _______________ EOS ::  END of Script ::::::::::::::::::::::::::::::::::::::::

 

 

#  #  Alternative to wget...

#  curl -o /dev/null  $test

#  #  curl is less verbose than wget. Speed is displayed as bytes per second:

#  #

#  #    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

#  #                                   Dload  Upload   Total   Spent    Left  Speed

#  #    0  500M    0 4931k    0     0  80993      0  1:47:53  0:01:02  1:46:51 81520

SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
Comments