Linux 测速(使用SpeedTest)

脚本介绍

speedtest 是一款使用 python 语言编写的轻量级的 linux 命令行测速工具,在 python2 以及 python3 的环境下都可以运行,基于 speedtest.net 基础框架来测量网络的上下行数据,安装也很简单,只要下载对应的 python 文件执行即可。

测速方法

1、先下载脚本(wget 下载或者下载好上传到服务器上)

wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py

2、为脚本授权

chmod a+rx speedtest.py
chown root:root speedtest.py

3、移至本机运行目录

mv speedtest.py /usr/local/bin/speedtest

4、执行测速

speedtest

5、输出结果如下示例

[root@ecs-test ~]# speedtest 
Retrieving speedtest.net configuration...
Testing from XXX Cloud (xxx.xx.xx.x)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by HK Broadband Network (XXX XXX) [0.87 km]: 3.969 ms
Testing download speed................................................................................
Download: 596.37 Mbit/s
Testing upload speed......................................................................................................
Upload: 8.80 Mbit/s

如果出现如下所示的找不到 python 环境的错误,对应解决即可:

[root@ecs-test ~]# speedtest 
/usr/bin/env: ‘python’: No such file or directory
[root@ecs-test ~]# python3 --version
Python 3.6.8
[root@ecs-test ~]# 
[root@ecs-test ~]# whereis python3
python3: /usr/bin/python3.6 /usr/bin/python3 /usr/bin/python3.6m /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz
[root@ecs-test ~]# sudo ln -s /usr/bin/python3 /usr/bin/python
[root@ecs-test ~]# speedtest 
Retrieving speedtest.net configuration...
Testing from XXX Cloud (xxx.xx.xx.x)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by HK Broadband Network (XXX XXX) [0.87 km]: 3.969 ms
Testing download speed................................................................................
Download: 596.37 Mbit/s
Testing upload speed......................................................................................................
Upload: 8.80 Mbit/s

如果主机连 python2 和 3 都没有,请先安装 python。

speedtest之docker容器

1、运行容器, 把容器 80 端口映射到主机 8080 端口

docker run -itd -p 8080:80 --name speedtest adolfintel/speedtest 

2、然后通过浏览器访问 http://xx.xx.x.x:8080 即可查看UI界面。

在这里插入图片描述

你可以用这个浏览器页面测试你的电脑和其他终端设备到服务器之间的速度。


(END)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catoop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值