欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用Python實現(xiàn)網(wǎng)絡(luò)測試的示例代碼

 更新時間:2022年04月26日 08:21:10   作者:Python 集中營  
Speedtest CLI 為命令行帶來 Speedtest 背后的可信技術(shù)和全球服務(wù)器網(wǎng)絡(luò)。本文將利用它進行網(wǎng)絡(luò)測試,感興趣的小伙伴可以了解一下

Speedtest CLI 專為軟件開發(fā)人員、系統(tǒng)管理員和計算機愛好者等打造,是 Ookla® 提供技術(shù)支持的首款正式 Linux 本機 Speedtest 應(yīng)用程序。

Speedtest CLI是使用python語言開發(fā)的,不僅可以直接在命令行運行。也可以作為python模塊在python IDE中直接調(diào)用。

首先,看一下如何在python應(yīng)用中進行調(diào)用,使用pip直接安裝。

pip install speedtest-cli

將該模塊直接導(dǎo)入到我們當(dāng)前的代碼塊中。

import speedtest as spt

創(chuàng)建網(wǎng)絡(luò)測試對象

spd = spt.Speedtest()

打印當(dāng)前可用于測試的服務(wù)器列表

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'}]}

獲取當(dāng)前最佳的測試服務(wù)器

spd.get_best_server()
print('測試開始,請稍等...')

獲得當(dāng)前的下載速度

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

獲得當(dāng)前的上傳速度

upload = int(spd.upload() / 1024 / 1024)

print(f'當(dāng)前下載速度為:{str(download)} MB/s')
print(f'當(dāng)前上傳速度為:{str(upload)} MB/s')
print('測試已完成!')

打印出最終的返回結(jié)果

測試開始,請稍等...
當(dāng)前下載速度為:12 MB/s
當(dāng)前上傳速度為:13 MB/s
測試已完成!

到此這篇關(guān)于利用Python實現(xiàn)網(wǎng)絡(luò)測試的示例代碼的文章就介紹到這了,更多相關(guān)Python網(wǎng)絡(luò)測試內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python實現(xiàn)查找所有程序的安裝信息

    python實現(xiàn)查找所有程序的安裝信息

    本文給大家分享的是使用python通過注冊表信息實現(xiàn)快速查找windows應(yīng)用程序的安裝信息的方法和代碼示例,有需要的小伙伴可以參考下
    2020-02-02
  • python3.7+anaconda 安裝opencv和dlib的問題及解決方法

    python3.7+anaconda 安裝opencv和dlib的問題及解決方法

    這篇文章主要介紹了python3.7+anaconda 安裝opencv和dlib的問題及解決方法,本文圖文并茂給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • 淺談Python類中的self到底是干啥的

    淺談Python類中的self到底是干啥的

    這篇文章主要介紹了淺談Python類中的self到底是干啥的,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Python機器學(xué)習(xí)中實現(xiàn)距離和相似性計算詳解

    Python機器學(xué)習(xí)中實現(xiàn)距離和相似性計算詳解

    這篇文章主要為大家詳細介紹了Python機器學(xué)習(xí)中實現(xiàn)距離和相似性計算的方法,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-03-03
  • python的setattr函數(shù)實例用法

    python的setattr函數(shù)實例用法

    在本篇文章里小編給大家整理了一篇關(guān)于python的setattr函數(shù)實例用法的相關(guān)知識點內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2020-12-12
  • 解決Python pandas plot輸出圖形中顯示中文亂碼問題

    解決Python pandas plot輸出圖形中顯示中文亂碼問題

    今天小編就為大家分享一篇解決Python pandas plot輸出圖形中顯示中文亂碼問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python初學(xué)者需要注意的事項小結(jié)(python2與python3)

    Python初學(xué)者需要注意的事項小結(jié)(python2與python3)

    這篇文章主要介紹了Python初學(xué)者需要注意的事項小結(jié),包括了python2與python3的一些區(qū)別,需要的朋友可以參考下
    2018-09-09
  • 深入了解Django View(視圖系統(tǒng))

    深入了解Django View(視圖系統(tǒng))

    這篇文章主要介紹了簡單了解Django View(視圖系統(tǒng)),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • Python3中.whl文件創(chuàng)建及使用

    Python3中.whl文件創(chuàng)建及使用

    本文主要介紹了Python3中.whl文件創(chuàng)建及使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Python中使用socks5設(shè)置全局代理的方法示例

    Python中使用socks5設(shè)置全局代理的方法示例

    這篇文章主要介紹了Python中使用socks5設(shè)置全局代理的方法示例,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04

最新評論