Jump to content
EduGeek EdSec 2026 is on Tuesday in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted (edited)

We're having some issues with the network speed in some locations. Until I can write a program that operates internally I whipped this one up that uses a module called speedtest-cli which polls speedtest.net

 

Be sure to install "speedtest-cli" and not "speedtest". The latter does nothing.

It's set to run every 300 seconds (5mins)

It saves the log on a network share with the computername as their username

You can use Pyinstaller to convert it to a single exe file

 

import speedtest
from datetime import datetime
import time
import sys
from socket import gethostname
import os

user = os.environ['USERNAME']
output = f"\\\\server\\share$\\tools\\speedtest\\{user.lower()}.txt"
if not os.path.exists(output):
   open(output,'w').close()

st = speedtest.Speedtest()
st.get_best_server()

def test():
   s = speedtest.Speedtest()
   s.get_best_server()
   s.download()
   s.upload()
   res = s.results.dict()
   return res["download"], res["upload"], res['server']["lat"]
   #alternative to lat you might want res['ping]


while True:
   d, u, p = test()
   now = datetime.now()
   datestr = now.strftime("%Y-%m-%d %H:%M")
   f = open(output, 'a')   
   try:
       print (f"[{datestr}]Download: {round(d/1048576,1)}MB Upload: {round(u/1048576,1)}MB Latency: {p}")
       f.write(f"[{datestr}]Download: {round(d/1048576,1)}MB Upload: {round(u/1048576,1)}MB Latency: {p}\n")
   except Exception as ex:
       print (f"[{datestr}]An exception of {type(ex)} occurred, {ex.args}")
       f.write(f"[{datestr}]An exception of {type(ex)} occurred, {ex.args}\n")
       pass

   f.close()    
   time.sleep(300)

 

edit: corrected a situation where sometimes it didn't append. Changed the filename to username.

Edited by browolf
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...