Linux网络速率测试
此程序是基于Python开发的脚本程序,利用了speedtest.net的服务来测量出上下行的宽带。Speedtest-cli能根据机房离测速服务器的物理距离来列出测速服务器,或者针对某一服务器进行测…
1. speedtest工具介绍
此程序是基于Python开发的脚本程序,利用了speedtest.net的服务来测量出上下行的宽带。Speedtest-cli能根据机房离测速服务器的物理距离来列出测速服务器,或者针对某一服务器进行测速,同时还能为你生成一个URL以便你分享你的测速结果。
!> 要在Linux上安装最新版本的speedtest-cli,你必须安装2.4-3.4或者更高版本的Python。
2. 安装speedtest-cli
安装speedtest-cli有两种方法。
-
用python-pip包管理器,
首先你需要安装python-pip包管理器,之后你就可以用pip命令来安装speedtest-cli
sudo apt install python-pip sudo pip install speedtest-cli如果要把speedtest-cli升级至最新版本,你需要输入以下命令
sudo pip install speedtest-cli --upgrade -
安装Python脚本,生成安装文件然后运行
首先要用wget命令从github上下来Python脚本,然后解压提取下载的文件(master.zip)
wget https://github.com/sivel/speedtest-cli/archive/master.zip unzip master.zip提取出文件后,进入目录speedtest-cli-master然后使脚本可以执行。
cd speedtest-cli-master/ chmod 755 speedtest_cli.py可以把脚本移动到/usr/bin文件夹,这样你就不用每次都输入完整的脚本路径了。
sudo mv speedtest_cli.py /usr/bin/
3. 用speedtest-cli测试速率
要测试你的下载与上传速度,只需要运行speedtest-cli命令,不需要带参数
python3 speedtest_cli.py
想要以字节计算数值,可以加入以下参数
python3 speedtest_cli.py --bytes
工具提供一个链接来下载由你的宽带测试结果生成的图片,加入 share参数即可;
python3 speedtest_cli.py --share
更多参数可以通过 --help 查看
usage: speedtest.py [-h] [--no-download] [--no-upload] [--single] [--bytes]
[--share] [--simple] [--csv]
[--csv-delimiter CSV_DELIMITER] [--csv-header] [--json]
[--list] [--server SERVER] [--exclude EXCLUDE]
[--mini MINI] [--source SOURCE] [--timeout TIMEOUT]
[--secure] [--no-pre-allocate] [--version]
Command line interface for testing internet bandwidth using speedtest.net.
--------------------------------------------------------------------------
https://github.com/sivel/speedtest-cli
optional arguments:
-h, --help show this help message and exit
--no-download Do not perform download test
--no-upload Do not perform upload test
--single Only use a single connection instead of multiple. This
simulates a typical file transfer.
--bytes Display values in bytes instead of bits. Does not
affect the image generated by --share, nor output from
--json or --csv
--share Generate and provide a URL to the speedtest.net share
results image, not displayed with --csv
--simple Suppress verbose output, only show basic information
--csv Suppress verbose output, only show basic information
in CSV format. Speeds listed in bit/s and not affected
by --bytes
--csv-delimiter CSV_DELIMITER
Single character delimiter to use in CSV output.
Default ","
--csv-header Print CSV headers
--json Suppress verbose output, only show basic information
in JSON format. Speeds listed in bit/s and not
affected by --bytes
--list Display a list of speedtest.net servers sorted by
distance
--server SERVER Specify a server ID to test against. Can be supplied
multiple times
--exclude EXCLUDE Exclude a server from selection. Can be supplied
multiple times
--mini MINI URL of the Speedtest Mini server
--source SOURCE Source IP address to bind to
--timeout TIMEOUT HTTP timeout in seconds. Default 10
--secure Use HTTPS instead of HTTP when communicating with
speedtest.net operated servers
--no-pre-allocate Do not pre allocate upload data. Pre allocation is
enabled by default to improve upload performance. To
support systems with insufficient memory, use this
option to avoid a MemoryError
--version Show the version number and exit
!> 提醒:报告中的延迟并不是确切的结果,不应该过于依赖它;这个数值可以当作相对延迟,这对你选择某一测试服务器来说是可靠的。同时,CPU和内存的容量会影响结果的准确度。
本文可自由转载与修改,但需保留作者署名与出处链接,不得用于商业用途,且衍生作品需以相同方式共享。 转载请注明:MacLodge's Blog · Linux网络速率测试