Test Internet Speed using Python
Python as a language offers various functionalities and has a wide range of applications. One such application we will be talking in this post is to measure speed of the internet using speedtest-cli library of Python.
We will be able to calculate download speed, upload speed, and ping using this library.
Library Used:
We will be using speedtest-cli library. It is a module that is used in a command-line interface used to measure the speed of the internet using speedtest.net.
To install it use the following command
pip install speedtest-cli
Implementation:
import speedtest #Import library
st = speedtest.Speedtest()
speedoption = int(input('''What speed do you want to test:
1) Download Speed
2) Upload Speed
3) Ping
Your Choice: '''))
if speedoption == 1:
print(st.download()) # To get download speed
elif speedoption == 2:
print(st.upload()) # To get upload speed
elif speedoption == 3:
servernames =[]
st.get_servers(servernames)
print(st.results.ping) #To get ping
else:
print("Invalid Choice")
Output:
We will be getting the following result on choosing following options 1,2,3 respectively-
Option 1:
What speed do you want to test: 1) Download Speed 2) Upload Speed 3) Ping Your Choice: 1 9298984.994032167
Option 2:
What speed do you want to test: 1) Download Speed 2) Upload Speed 3) Ping Your Choice: 2 4658825.902497861
Option 3:
What speed do you want to test: 1) Download Speed 2) Upload Speed 3) Ping Your Choice: 3 0
So, with this way, we are able to check the internet speed with Python.
This is how it works. For any queries contact harshil.gupta95@gmail.com
Leave a Reply