検索
ホームページバックエンド開発Python チュートリアルPython を使用してネットワーク テストを実装する方法

Speedtest CLI は、ソフトウェア開発者、システム管理者、およびコンピュータ愛好家向けに構築された、Ookla® を利用した初の公式 Linux ネイティブ Speedtest アプリケーションです。

Python 言語で書かれた Speedtest CLI をコマンド ラインで直接実行して、ネットワーク速度テストを実装できます。 Python IDE で Python モジュールとして直接呼び出すこともできます。

まず、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/秒
現在のアップロード速度: 13 MB/秒
テストは完了しました。

以上がPython を使用してネットワーク テストを実装する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明
この記事は亿速云で複製されています。侵害がある場合は、admin@php.cn までご連絡ください。
リストと配列の選択は、大規模なデータセットを扱うPythonアプリケーションの全体的なパフォーマンスにどのように影響しますか?リストと配列の選択は、大規模なデータセットを扱うPythonアプリケーションの全体的なパフォーマンスにどのように影響しますか?May 03, 2025 am 12:11 AM

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

Pythonのリストと配列にメモリがどのように割り当てられるかを説明します。Pythonのリストと配列にメモリがどのように割り当てられるかを説明します。May 03, 2025 am 12:10 AM

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

Pythonアレイ内の要素のデータ型をどのように指定しますか?Pythonアレイ内の要素のデータ型をどのように指定しますか?May 03, 2025 am 12:06 AM

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

Numpyとは何ですか、そしてなぜPythonの数値コンピューティングにとって重要なのですか?Numpyとは何ですか、そしてなぜPythonの数値コンピューティングにとって重要なのですか?May 03, 2025 am 12:03 AM

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

「隣接するメモリ割り当て」の概念と、配列にとってその重要性について説明します。「隣接するメモリ割り当て」の概念と、配列にとってその重要性について説明します。May 03, 2025 am 12:01 AM

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

Pythonリストをどのようにスライスしますか?Pythonリストをどのようにスライスしますか?May 02, 2025 am 12:14 AM

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

Numpyアレイで実行できる一般的な操作は何ですか?Numpyアレイで実行できる一般的な操作は何ですか?May 02, 2025 am 12:09 AM

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Pythonを使用したデータ分析では、配列はどのように使用されていますか?Pythonを使用したデータ分析では、配列はどのように使用されていますか?May 02, 2025 am 12:09 AM

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 Linux 新バージョン

SublimeText3 Linux 新バージョン

SublimeText3 Linux 最新バージョン

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール