Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to realize Network Test

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge about how to use Python to achieve network testing. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

Built for software developers, system administrators and computer enthusiasts, Speedtest CLI is the first official Linux native Speedtest application supported by Ookla ®.

Speedtest CLI is developed in the Python language and can not only be run directly on the command line. It can also be called directly in python IDE as a python module.

First, take a look at how to make a call in a python application and install it directly using pip.

Pip install speedtest-cli

Import the module directly into our current code block.

Import speedtest as spt

Create a network test object

Spd = spt.Speedtest ()

Print a list of servers currently available for testing

From pprint import pprintpprint (spd.get_servers ()) # {721.5702755019188: [{'cc':' CN',# 'country':' China',# 'dudes: 721.5702755019188 #' host': 'speedtest1.he.chinamobile.com:8080',#' id': '41912' # 'lat':' 38.0428 'China Mobile Hebei Co., Ltd', #' lon': '114.5149', 'name':' Shijiazhuang', # 'sponsor':' # 'url':' http://speedtest1.he.chinamobile.com:8080/speedtest/upload.php'}],# 776.2668436087947: [{'cc':' CN',# 'country':' China',# 'dudes: 776.2668436087947pr #' host': '5gtest.shangdu.compur80' # 'id':' 36646 'China Unicom HeNan #' lat': '34.7466' lon': '113.6253' 'China Unicom HeNan 5G' # 'url':' http://5gtest.shangdu.com:8080/speedtest/upload.php'}],# 1051.7168853741107: [{'cc':' MN',# 'country':' Mongolia',# 'speedtest.gemnet.mn:8080': 1051.7168853741107 # 'id':' 2853 'sponsor': #' lat': '47.9200' lon': '106.9200' 'Ulaanbaatar',#' sponsor': 'Gemnet LLC' # 'url':' http://speedtest.gemnet.mn:8080/speedtest/upload.php'},# {'cc':' MN',# 'country':' Mongolia',# 'dudes: 1051.7168853741107 # 'host':' speedtest1.kewiko.mn:8080',# 'id':' 30772 'name':' Ulaanbaatar' # 'lat':' 47.9200''lon':' 106.9200' # 'sponsor':' Kewiko LLC',# 'url':' http://speedtest1.kewiko.mn:8080/speedtest/upload.php'}],# 1339.1170164273938: [{'cc':' CN',# 'country':' China',# 'dudes: 1339.1170164273938 # 'host':' 5gnanjing.speedtest.jsinfo.NetVANG 8080 name': Nanjing' # 'id':' 26352 Nanjing' # 'lat':' 32.0500 charm # 'lon':' 118.7667 # 'sponsor':' China Telecom JiangSu 5Grain http://5gnanjing.speedtest.jsinfo.net:8080/speedtest/upload.php'}],# # 'url':' http://5gnanjing.speedtest.jsinfo.net:8080/speedtest/upload.php'}],# 1340.7612716854985: [{'cc':' CN',# 'country':' China',# 'dwells: 1340.7612716854985 # 'host':' speedtest02.js165.com:8080',# 'id':' 13704 'name':' Nanjing' # 'lat':' 32.0602''lon':' 118.7968'' # 'sponsor':' China Unicom',# 'url':' http://speedtest02.js165.com:8080/speedtest/upload.php'}],# 1381.912955930571: [{'cc':' CN',# 'country':' China',# 'dwells: 1381.9129755930571 # 'host':' speedtest.zjmobile.com:8080',# 'id':' 17320 'name':' ZhenJiang' # 'lat':' 32.2069 'lon':' 119.4490'' # 'sponsor':' China Mobile JiangSu 5Grain http://speedtest.zjmobile.com:8080/speedtest/upload.php'}],# # 'url':' http://speedtest.zjmobile.com:8080/speedtest/upload.php'}],# 1489.08809618835: [{'cc':' RU',# 'country':' Russia',# 'dwells: 1489.08809618835 # 'host':' speedtest-ude.edinos.ru:8080',# 'id':' 36254 'name':' Ulan-Ude' # 'lat':' 51.8336''lon':' 107.5840' # 'sponsor':' EDINOS',# 'url':' http://speedtest-ude.edinos.ru:8080/speedtest/upload.php'}],# 1542.170901504592: [{'cc':' RU',# 'country':' Russia',# 'dudes: 1542.170901504592 # 'host':' speedtest.bteleport.ru:8080',# 'id':' 18543 'name':' Irkutsk' # 'lat':' 52.2757''lon':' 104.3087'' # 'sponsor':' Baikal Teleport',# 'url':' http://speedtest.bteleport.ru:8080/speedtest/upload.php'},# {'cc':' RU',# 'country':' Russia',# 'dudes: 1542.170901504592 # 'host':' speedtest-irkutsk.fttb.beeline.ru:8080',# 'id':' 31472 'name':' Irkutsk' # 'lat':' 52.2757''lon':' 104.3087'' # 'sponsor':' Beeline',# 'url':' http://speedtest-irkutsk.fttb.beeline.ru:8080/speedtest/upload.php'}]}

Get the best current test server

Spd.get_best_server () print ('Test begins, please wait a moment.')

Get the current download speed

Download = int (spd.download () / 1024 / 1024)

Get the current upload speed

Upload = int (spd.upload () / 1024 / 1024) print (f 'current download speed is: {str (download)} MB/s') print (f' current upload speed is: {str (upload)} MB/s') print ('test completed!')

Print out the final return result

The test begins, please wait a moment.

The current download speed is 12 MB/s

The upload speed is 13 MB/s.

The test is complete!

These are all the contents of the article "how to use Python to achieve Network testing". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 290

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report