它是一款面向開發人員的互聯網連接測量工具,Speedtest CLI 為命令列帶來 Speedtest 背后的可信技術和全球服務器網路,
【閱讀全文】
Speedtest CLI 專為軟體開發人員、系統管理員和計算機愛好者等打造,是 Ookla? 提供技術支持的首款正式 Linux 本機 Speedtest 應用程式,
Speedtest CLI是使用python語言開發的,不僅可以直接在命令列運行,也可以作為python模塊在python IDE中直接呼叫,
首先,看一下如何在python應用中進行呼叫,使用pip直接安裝,
pip install speedtest-cli
將該模塊直接匯入到我們當前的代碼塊中,
import speedtest as spt
創建網路測驗物件
spd = spt.Speedtest()
列印當前可用于測驗的服務器串列
from pprint import pprint
pprint(spd.get_servers())
# {721.5702755019188: [{'cc': 'CN',
# 'country': 'China',
# 'd': 721.5702755019188,
# 'host': 'speedtest1.he.chinamobile.com:8080',
# 'id': '41912',
# 'lat': '38.0428',
# 'lon': '114.5149',
# 'name': '石家莊',
# 'sponsor': 'China Mobile Hebei Co., Ltd',
# 'url': 'http://speedtest1.he.chinamobile.com:8080/speedtest/upload.php'}],
# 776.2668436087947: [{'cc': 'CN',
# 'country': 'China',
# 'd': 776.2668436087947,
# 'host': '5gtest.shangdu.com:8080',
# 'id': '36646',
# 'lat': '34.7466',
# 'lon': '113.6253',
# 'name': 'Zhengzhou',
# 'sponsor': 'China Unicom HeNan 5G',
# 'url': 'http://5gtest.shangdu.com:8080/speedtest/upload.php'}],
# 1051.7168853741107: [{'cc': 'MN',
# 'country': 'Mongolia',
# 'd': 1051.7168853741107,
# 'host': 'speedtest.gemnet.mn:8080',
# 'id': '2853',
# 'lat': '47.9200',
# 'lon': '106.9200',
# 'name': 'Ulaanbaatar',
# 'sponsor': 'Gemnet LLC',
# 'url': 'http://speedtest.gemnet.mn:8080/speedtest/upload.php'},
# {'cc': 'MN',
# 'country': 'Mongolia',
# 'd': 1051.7168853741107,
# 'host': 'speedtest1.kewiko.mn:8080',
# 'id': '30772',
# 'lat': '47.9200',
# 'lon': '106.9200',
# 'name': 'Ulaanbaatar',
# 'sponsor': 'Kewiko LLC',
# 'url': 'http://speedtest1.kewiko.mn:8080/speedtest/upload.php'}],
# 1339.1170164273938: [{'cc': 'CN',
# 'country': 'China',
# 'd': 1339.1170164273938,
# 'host': '5gnanjing.speedtest.jsinfo.net:8080',
# 'id': '26352',
# 'lat': '32.0500',
# 'lon': '118.7667',
# 'name': 'Nanjing',
# 'sponsor': 'China Telecom JiangSu 5G',
# 'url': 'http://5gnanjing.speedtest.jsinfo.net:8080/speedtest/upload.php'}],
# 1340.7612716854985: [{'cc': 'CN',
# 'country': 'China',
# 'd': 1340.7612716854985,
# 'host': 'speedtest02.js165.com:8080',
# 'id': '13704',
# 'lat': '32.0602',
# 'lon': '118.7968',
# 'name': 'Nanjing',
# 'sponsor': 'China Unicom',
# 'url': 'http://speedtest02.js165.com:8080/speedtest/upload.php'}],
# 1381.9129755930571: [{'cc': 'CN',
# 'country': 'China',
# 'd': 1381.9129755930571,
# 'host': 'speedtest.zjmobile.com:8080',
# 'id': '17320',
# 'lat': '32.2069',
# 'lon': '119.4490',
# 'name': 'ZhenJiang',
# 'sponsor': 'China Mobile JiangSu 5G',
# 'url': 'http://speedtest.zjmobile.com:8080/speedtest/upload.php'}],
# 1489.08809618835: [{'cc': 'RU',
# 'country': 'Russia',
# 'd': 1489.08809618835,
# 'host': 'speedtest-ude.edinos.ru:8080',
# 'id': '36254',
# 'lat': '51.8336',
# 'lon': '107.5840',
# 'name': 'Ulan-Ude',
# 'sponsor': 'EDINOS',
# 'url': 'http://speedtest-ude.edinos.ru:8080/speedtest/upload.php'}],
# 1542.170901504592: [{'cc': 'RU',
# 'country': 'Russia',
# 'd': 1542.170901504592,
# 'host': 'speedtest.bteleport.ru:8080',
# 'id': '18543',
# 'lat': '52.2757',
# 'lon': '104.3087',
# 'name': 'Irkutsk',
# 'sponsor': 'Baikal Teleport',
# 'url': 'http://speedtest.bteleport.ru:8080/speedtest/upload.php'},
# {'cc': 'RU',
# 'country': 'Russia',
# 'd': 1542.170901504592,
# 'host': 'speedtest-irkutsk.fttb.beeline.ru:8080',
# 'id': '31472',
# 'lat': '52.2757',
# 'lon': '104.3087',
# 'name': 'Irkutsk',
# 'sponsor': 'Beeline',
# 'url': 'http://speedtest-irkutsk.fttb.beeline.ru:8080/speedtest/upload.php'}]}
獲取當前最佳的測驗服務器
spd.get_best_server()
print('測驗開始,請稍等...')
獲得當前的下載速度
download = int(spd.download() / 1024 / 1024)
獲得當前的上傳速度
upload = int(spd.upload() / 1024 / 1024)
print(f'當前下載速度為:{str(download)} MB/s')
print(f'當前上傳速度為:{str(upload)} MB/s')
print('測驗已完成!')
列印出最終的回傳結果
測驗開始,請稍等...
當前下載速度為:12 MB/s
當前上傳速度為:13 MB/s
測驗已完成!

【往期精彩】
模型已經寫好了,怎么表白就看你的了!
如何實作根據照片獲取地理位置及如何防御照片泄漏地理位置!
又是櫻花盛開的季節,使用小烏龜來畫一顆櫻花樹吧!
Python 讀取PDF檔案為文本字符并轉換為音頻...
python 獲取最新房價資訊-以北京房價為例
辦公自動化:Image圖片轉換成PDF檔案存盤...
python做一個微型美顏圖片處理器,十行代碼即可完成...
用python做一個文本翻譯器,自動將中文翻譯成英文,超方便的!
小王,給這2000個客戶發一下節日祝福的郵件...
python 一行命令開啟網路間的檔案共享...
PyQt5 批量洗掉 Excel 重復資料,多個檔案、自定義重復項一鍵洗掉...
再見XShell,這款國人開源的終端命令列工具更nice!
歡迎關注作者公眾號【Python 集中營】,專注于后端編程,每天更新技術干貨,不定時分享各類資料!轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464025.html
標籤:Python
