Most advanced computer users know about speedtest.net that helps testing your internet bandwidth. While it is a great tool, it has only flash version available on their web site and there are Android and iOS apps for your mobile phones, but there were no tools available for Linux servers without GUI.
Back in 2009 I made a PHP script that tested network speed, wrote the results to text file and generated PNG graphs to be shown on web. It used speedtest.net partner servers and it got the data usage from ifconfig thus making it read the total bandwidth, not just what had been left for the php script itself. I set it up on my home router so I could prove my ISP that their internet is far form what they advertised.
I also uploaded it to Sourceforge and forgot about it’s existence for some time.
Years have passed and it has been downloaded almost 17 000 times, even though it doesn’t really work in every case and it wasn’t that easy to set up.
So I figured I should make a new version, written in Python (just to practice it), and so I did.
The new Tespeed is available at Github: https://github.com/Janhouse/tespeed
It is licensed under MIT license.
There are still some bugs and planned features left to sort out, but after testing it on multiple computers it is working fine.
The new version finds closest servers and then picks the one with lowest latency.
You can also get a list of all available servers (and see the approximate distance to them) by using list-servers command.
Please send me some feedback so I could make it better.
And go thank speedtest.net for this great service. š
Downloaded and installed. Works fine in my computer… Now i have an nice and simple command line tool for getting a network speed measure. Thanks for sharing Janis.
Just used your tool, works pretty good ! š
Just a few things i noticed:
When testing it on different hosts i got a 404 on one of them.
I found which server gave back the 404 list:(http://speedtest.net/speedtest-servers.php?x=1351254108.44) search for: sponsor=”Vodafone NL”
This server seems to be detected at 0ms and sets a wrong url in de server_list var.
To reproduce find ‘def LoadServers(self):’
then after ‘for server in servers:’ add the following line ‘if server.attrib[‘sponsor’] == “Vodafone NL”‘
My guess is that when url contains ‘.aspx’ the url is 1 char longer than the .php version which causes the url to end with /u instead of just /
(see the ‘-10’ part in the for loop)
Maybe better to cut of everything after last / then just to remove the last 10 chars.
— For the google’s :
Also i do a quick test on some machines i just copy past this line in:
wget -Otespeed.py ‘https://raw.github.com/Janhouse/tespeed/master/tespeed.py’ && chmod u+x tespeed.py && ./tespeed.py
note most of the centos machines i have don’t have python-lxml installed so if you get the ‘ImportError: No module named lxml’ run
‘sudo yum install python-lxml -y’
Thanks, I think someone has already reported this on Github and Iām going to add the fix in a free moment.
Maybe you should add a feature to manually choose the SpeedTest node we want to use. Because I have some servers on various places and would like to compare them against the same Node (to get more comparable data). I know this wouldn’t give perfect results, but …
Thanks anyway, a very useful tool that I found just when I wanted to write one myself š *thumbsup*
You can, I think I wrote about it in the README.
For example:
./tespeed.py http://www.ping.lv/speedtest/
Heres just easyr way- just enter command and see speed with no installations or hassle
wget -O/dev/null speedtest.pixelwolf.ch
Sure, you can do that but it shows only download speed and tests with single server that is probably not close to yours.
this is perfect! i spent hours trying to find out how to determine my VPS’ upload speed and this program solved it! thanks a lot!
I am glad it was useful for you. š
Hi Janhouse,
I have successfully installed your utility on a local Ubuntu system and it works great!
I have also installed it on a remote server running CentOS5. This gives me some errors.
Here is a listing of the output from the program:
root@server [/usr/local/speedtest]# ./testspeed.py
Getting ready. Use parameter -h or –help to see available features.
Loading speedtest configuration…
IP: 71.40.108.2; Lat: 29.589200; Lon: -98.293900; ISP: Road Runner
Loading server list…
Looking for closest and best server…
Testing latency…
Traceback (most recent call last):
File “./testspeed.py”, line 533, in ?
main(args)
File “./testspeed.py”, line 518, in main
t=TeSpeed(args.listservers and ‘list-servers’ or args.server, args.listservers, args.store and True or False, args.suppress and True or False, args.unit and True or False)
File “./testspeed.py”, line 99, in __init__
self.TestSpeed()
File “./testspeed.py”, line 483, in TestSpeed
self.FindBestServer()
File “./testspeed.py”, line 356, in FindBestServer
best=self.TestLatency(self.Closest([self.config[‘lat’], self.config[‘lon’]], self.server_list, self.bestServers))
File “./testspeed.py”, line 146, in TestLatency
now=self.TestSingleLatency(server[‘url’]+”latency.txt?x=” + str( time.time() ))*1000
File “./testspeed.py”, line 174, in TestSingleLatency
response = urllib2.urlopen(request, timeout = 5)
TypeError: urlopen() got an unexpected keyword argument ‘timeout’
root@server [/usr/local/speedtest]#
What could be the problem?
Python version is 2.4.3 from CentOS
I had to install: python-argparse-1.2.1-2.el5.noarch.rpm, python-lxml-1.3.4-1.el5.rf.x86_64.rpm, and python-multiprocessing-2.6.2.1-3.el5.x86_64.rpm
I hope you can give me a clue as to what is going wrong,
Thanks for this cool software,
Ralph
Updating Python should help: http://stackoverflow.com/a/4122184/1246756
You could also try removing timeout parameter from urllib2.urlopen calls.
After installing several missing packages, I get this. It’s a Centos 5 box.
root@server [~/speedtest/tespeed-master]# ./tespeed.py
Traceback (most recent call last):
File “./tespeed.py”, line 12, in ?
from lxml import etree
ImportError: libexslt.so.0: cannot open shared object file: No such file or directory
Hello.
Now I am getting this error, probably because centos 5.8 old phyton version.
File “./tespeed.py”, line 223, in TestSingleLatency
response = urllib2.urlopen(request, timeout = 5)
TypeError: urlopen() got an unexpected keyword argument ‘timeout’
Is there a workaround?
thanks!
Ok, now i see this issue has been commented before, sorry!
Ok, as suggested I removed timeout parameter, I’m trying to avoid pythonupgrade. Now I get this:
Loading server list…
Looking for closest and best server…
Testing latency…
18 ms latency for http://speed01.il.towerstream.com/speedtest/ (Towerstream, Chicago, IL, United States) [0.07 km]
18 ms latency for http://sto-chic-01.sys.comcast.net/speedtest/ (Comcast, Chicago, IL, United States) [0.07 km]
40 ms latency for http://chi.fastsoft.net/speedtest/ (FastSoft, Chicago, IL, United States) [0.07 km]
19 ms latency for http://speedtest.servercentral.net/speedtest/ (ServerCentral, Chicago, IL, United States) [0.07 km]
19 ms latency for http://speedtest-1.silverip.net/speedtest/ (SilverIP Communications, Chicago, IL, United States) [3.21
Failed downloading.
Failed downloading.
Failed downloading.
Failed downloading.
Failed downloading.
Failed downloading.
….
I finally got downloading test to work but for some reason uploading fails š
Download size: 126.52 MiB; Downloaded in 0.65 s
Download speed: 194.23 Mbit/s
Download size: 506.01 MiB; Downloaded in 2.88 s
Download speed: 175.95 Mbit/s
Download size: 506.01 MiB; Downloaded in 4.58 s
Download speed: 110.50 Mbit/s
Download size: 506.01 MiB; Downloaded in 3.58 s
Download speed: 141.52 Mbit/s
Download size: 506.01 MiB; Downloaded in 3.02 s
Download speed: 167.32 Mbit/s
Download size: 506.01 MiB; Downloaded in 3.43 s
Download speed: 147.60 Mbit/s
Failed uploading.
Failed uploading.
Failed uploading.
Failed uploading.
Failed uploading.
Failed uploading.
Failed uploading.
Adding date and time fields to the front of the CSV output would be a nice.
tespeed-master/tespeed.py -w -s | (read x; echo “$(date +’%y-%m-%d %H:%M:%S’): $x” ) >>/home/myself/tespeed.out
Installed on Ubuntu server 12.04 LTS. Works nicely.
However, I’ve noticed something interesting. Download and upload speed decreases quite a lot in the last test (2 threads). Sample output:
Download size: 1.96 MiB; Downloaded in 0.12 s
Download speed: 16.91 Mbit/s
Download size: 1.96 MiB; Downloaded in 0.12 s
Download speed: 17.04 Mbit/s
Download size: 8.09 MiB; Downloaded in 0.29 s
Download speed: 28.11 Mbit/s
Download size: 8.09 MiB; Downloaded in 0.29 s
Download speed: 28.32 Mbit/s
Download size: 17.89 MiB; Downloaded in 0.55 s
Download speed: 32.62 Mbit/s
Download size: 17.89 MiB; Downloaded in 0.55 s
Download speed: 32.33 Mbit/s
Download size: 31.78 MiB; Downloaded in 0.89 s
Download speed: 35.71 Mbit/s
Download size: 71.49 MiB; Downloaded in 10.46 s
Download speed: 6.84 Mbit/s
Upload size: 2.10 MiB; Uploaded in 0.55 s
Upload speed: 3.81 Mbit/s
Upload size: 2.10 MiB; Uploaded in 0.51 s
Upload speed: 4.07 Mbit/s
Upload size: 8.39 MiB; Uploaded in 2.09 s
Upload speed: 4.01 Mbit/s
Upload size: 8.39 MiB; Uploaded in 14.54 s
Upload speed: 0.58 Mbit/s
Is this something to do with Python thread performance or should I have a serious conversation with my ISP?
No, it is fine. Just look at the highest speeds.
Hi,
it working very well, but i have two request:
1. Is possible generate a log file with test? I want add it to cronjob every 4 hours… but –csv or -w not work
2. Is possible get the image result, but how get it?
Thanks.
Hi Janis,
I’m a complete amateur but would really like to get this neat little utility going. I have installed Python 2.7.5 (http://www.python.org/ftp/python/2.7.5/python-2.7.5.amd64.msi) and lxml (https://pypi.python.org/packages/2.7/l/lxml/lxml-3.2.1.win-amd64-py2.7.exe#md5=f981319fb3a0d7e2aa19889081e8aa87) and have then run the script in the Windows CLI as “python tespeed.py”.
This gets started very nicely, testing the latency for 5 servers, but then runs into an error like this:
Process Process-2:
Traceback (most recent call last)
File “C:\Python27\lib\multiprocessing\process.py”, line 258, in _bootstrap self.run()
File “C:\Python27\lib\multiprocessing\process.py”, line 114, in run self._target(*self._args, **self._kwargs)
File “C:\Python27\tespeed.py”, line 314, in AsyncGet print_debug( \r’)
File “C:\Python27\tespeed.py”, line 585, in print_debug
if args.suppress!=True:
NameError: global name ‘args’ is not defined
Do you have any suggestions for what is going wrong & what to do about it?
Many thanks
Tim
Any ideas on this “global name ‘args'” error? I have this same issue with Python 2.7 for Windows.
David
Hi Janhouse,
Is it possible to add result time? say like “Download Speed at 11-Jul-2013 22:22:11 is 8.9MB. this will help monitor the speed test.
also save result in txt or csv file?
i tried modifiying it but with no success.
thanks,
piway
This script is excellent, thank you JÄnis
argparse is no longer a valid install module for apt-get. I have tried apt-get install python-argparse but it has been deleted a little while back.
I know my errors are similar to the ones shown above but your answer back then was to update python. I am updated. Just installed 2.7.3 from Ubuntu with the apt-get install python-lxml …it did everything needed but it’s still not working.
I am getting a number of errors when I run:
Loading server list…
Looking for closest and best server…
Testing latency…
40 ms latency for http://speedtest1.hivelocity.net/speedtest/ (Hivelocity Hosting, Tampa, FL, United States) [5.38 km]
41 ms latency for http://speedtestnet.rapidsys.com/speedtest/ (Rapid Systems, Tampa, FL, United States) [5.38 km]
46 ms latency for http://fl.suncoastbroadband.com/speedtest/speedtest/ (Suncoast Broadband, Sarasota, United States) [8.23 km]
28 ms latency for http://speedtest.nefcom.net/speedtest/ (Nefcom Internet, Macclenny, FL, United States) [56.52 km]
42 ms latency for http://speedtest.t3com.net/speedtest/ (T3 Communications, Inc., Fort Myers, FL, United States) [75.16 km]
Traceback (most recent call last):
File “./tespeed.py”, line 661, in
main(args)
File “./tespeed.py”, line 636, in main
chunksize=args.chunksize
File “./tespeed.py”, line 148, in __init__
self.TestSpeed()
File “./tespeed.py”, line 586, in TestSpeed
self.TestDownload()
File “./tespeed.py”, line 552, in TestDownload
sizes, took=self.AsyncRequest(url, thrds )
File “./tespeed.py”, line 426, in AsyncRequest
d=Manager().dict()
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 667, in temp
token, exp = self._create(typeid, *args, **kwds)
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 565, in _create
conn = self._Client(self._address, authkey=self._authkey)
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 175, in Client
answer_challenge(c, authkey)
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 413, in answer_challenge
message = connection.recv_bytes(256) # reject large message
IOError: [Errno 11] Resource temporarily unavailable
The same …
Help please !
Hi
I can workaround this, but using this on my Raspberry Pi, I get the following error
pi@RPI-16 ~/scripts $ python speedtest.py
Traceback (most recent call last):
File “speedtest.py”, line 8, in
from SocksiPy import socks
ImportError: No module named SocksiPy
I can get it work if the speedtest.py is placed inside the tespeed directory-which is where the SocksiPy resides.I’m a bit of a Linux newbie-does this sound right?
Thanks-great script, by the way!
modify your script:
use:
import socks
instead of:
from SocksiPy import socks
Hi,
I am unable to run it on windows.
I have downloaded the socksipy file to library.
when i am running through CMD it shows me error at no module named socksipy.
Could you help me with that?
I found out that you can install missing modules using easy_install.py:
c:\Python27\Lib\site-packages>easy_install.py argparse lxml
But i’m still stuck with
NameError: global name āargsā is not defined
Error
NameError: global name āargsā is not defined
on Windows Server 2012 with Python 27 solved by commenting out row 604.tespeed gives me strangely low results.
On same server through site a can get 350 mbit/s down and 300 mbit/s up, but tespeed show results around 50 mbit/s down and 10 mbit/s up, and ‘-n ‘ seem to have no effect event when i don’t specify what server to use
I’m not sure if you are aware, but there is another command line utility for speedtest.net (written in Python) that has been available for a few years. It is available at https://github.com/sivel/speedtest-cli (installable via `pip install –user speedtest-cli`). I’m curious to try this out and see how it compares. Thanks!