网络在线测速、软件测速、命令行测速的工具汇总
当发现上网速度变慢时,人们通常会先首先测试自己的电脑到网络服务提供商(通常被称为“最后一公里”)的网络连接速度。
在可用于测试宽带速度的网站中,Speedtest.net也许是使用最广泛的。Speedtest.net的工作原理并不复杂:它在你的浏览器中加载JavaScript代码并自动检测离你最近的Speedtest.net服务器,然后向服务器发送HTTP GET and POST请求来测试上行/下行网速。在没有图形化桌面时,例如当你通过命令行远程登陆服务器或使用没有图形界面的操作系统,基于flash、界面友好的Speedtest.net将无法工作。幸运的是,Speedtest.net提供了一个命令行版本:speedtest-cli ,下面将演示如何在Linux的命令行中使用speedtest-cli来测试宽带连接速度。
在线测速测速的工具
便民查询网:https://wangsuceshi.51240.com
在线测网速:https://m.cncn.com/tool/cewangsu
webkaka:http://www.webkaka.com
命令行测速的工具
Linux下如何测量下载和上传的速度?
speedtest (推荐)
Github:https://github.com/sivel/speedtest-cli
speedtest 是一个用Python编写的轻量级Linux命令行工具,在Python2.4至3.4版本下均可运行。
speedtest 是基于Speedtest.net的基础架构来测量网络的上/下行速率。
speedtest 安装很简单,只需要下载其Python脚本文件。
Ubuntu 安装:sudo apt-get install speedtest-cli (CentOS不支持)
CentOS 安装:
先安装扩展源 EPEL,由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目
yum -y install epel-release
yum -y install gcc gcc-g++ python python-devel python-pip
Python 安装:
1、pip install speedtest-cli (推荐)
# pip install speedtest-cli Collecting speedtest-cli Downloading http://mirrors.aliyun.com/pypi/packages/c4/44/dfebd38c5fb35aae0a7279e2a3ffe33ca65edb449a586b93addc8d409a71/speedtest_cli-2.1.2-py2.py3-none-any.whl Installing collected packages: speedtest-cli Successfully installed speedtest-cli-2.1.2
2、easy_install speedtest-cli
# easy_install speedtest-cli Searching for speedtest-cli Reading http://mirrors.aliyun.com/pypi/simple/speedtest-cli/ Downloading http://mirrors.aliyun.com/pypi/packages/5c/c8/296057f78f16721863f9edb5abdb0d2648c5c6932697f29d80d920fdcd91/speedtest-cli-2.1.2.tar.gz#sha256=cf1d386222f94c324e3125ba9a0d187e46d4a13dca08c023bdb9a23096be2e54 Best match: speedtest-cli 2.1.2 Processing speedtest-cli-2.1.2.tar.gz Writing /tmp/easy_install-VBZUL5/speedtest-cli-2.1.2/setup.cfg Running speedtest-cli-2.1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-VBZUL5/speedtest-cli-2.1.2/egg-dist-tmp-2pmvbD zip_safe flag not set; analyzing archive contents... Moving speedtest_cli-2.1.2-py2.7.egg to /usr/lib/python2.7/site-packages Adding speedtest-cli 2.1.2 to easy-install.pth file Installing speedtest script to /usr/bin Installing speedtest-cli script to /usr/bin Installed /usr/lib/python2.7/site-packages/speedtest_cli-2.1.2-py2.7.egg Processing dependencies for speedtest-cli Finished processing dependencies for speedtest-cli
3、Github
pip install git+https://github.com/sivel/speedtest-cli.git or git clone https://github.com/sivel/speedtest-cli.git cd speedtest-cli python setup.py install
Just download (Like the way it used to be)
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py chmod +x speedtest-cli or curl -Lo speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py chmod +x speedtest-cli
speedtest 和 speedtest-cli
# which speedtest /bin/speedtest # # which speedtest-cli /bin/speedtest-cli # # ll /bin/speedtest -rwxr-xr-x 1 root root 404 Dec 13 20:10 /bin/speedtest # ll /bin/speedtest-cli -rwxr-xr-x 1 root root 412 Dec 13 20:10 /bin/speedtest-cli
使用帮助
speedtest-cli --help
# speedtest-cli --help usage: speedtest-cli [-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
测速命令
speedtest-cli
# speedtest-cli Retrieving speedtest.net configuration... Testing from Hangzhou Alibaba Advertising Co.,Ltd. (47.106.126.167)... Retrieving speedtest.net server list... Selecting best server based on ping... Hosted by China Mobile Zhejiang 5G (Ningbo) [141.76 km]: 33.765 ms Testing download speed................................................................................ Download: 226.15 Mbit/s Testing upload speed................................................................................................ Upload: 1.32 Mbit/s # # speedtest-cli Retrieving speedtest.net configuration... Cannot retrieve speedtest configuration ERROR: timed out # speedtest-cli Retrieving speedtest.net configuration... Testing from Hangzhou Alibaba Advertising Co.,Ltd. (47.106.126.167)... Retrieving speedtest.net server list... Selecting best server based on ping... Hosted by China Mobile Zhejiang 5G (Ningbo) [141.76 km]: 28.268 ms Testing download speed................................................................................ Download: 180.62 Mbit/s Testing upload speed................................................................................................ Upload: 1.23 Mbit/s
说明:
speedtest-cli 有连接失败的,因为墙内大局域网连接墙外很慢,国内一言难尽,脱离世界,必将落后!
当然对于测试结果,一般在实际应用中不一定能达到这个值,仅作为参考使用
例如:上面购买的带宽是 1Mb/s,实际测速结果 上传 1.23 Mbit/s,下载 180.62 Mbit/s,均大于购买的 1Mb/s
speedtest-cli 其他功能
speedtest-cli --share
如果你愿意分享测试结果,你可以使用参数“--share”。
它将会把你的测试结果上传到Speedtest.net服务器并以图形的方式分享给其他人。
speedtest-cli --list
如果你对目前所有可用的Speedtest.net服务器感兴趣,你可以使用参数“--list”。
它会打印出所有的Speedtest.net服务器(按照离你的地理距离由近及远排序)
speedtest-cli --server 2016
每个服务器的前面都有一个与其对应的ID。如果想使用指定的服务器来测试你的网速,你只需要在speedtest-cli命令后指定其ID即可。
例如,如果想使用在Washington DC的服务器,你只需要指定相对应的服务器ID,例如:ID = 2016
Linux 查看网络即时网速
1、sar
命令格式:sar -n DEV 1 3
说明:
1 代表一秒统计并显示一次
3 代表统计三次
使用 top、htop 等工具,就更方便简单了,不过这个更灵活
测速实例:
# sar -n DEV 1 3 Linux 3.10.0-957.27.2.el7.x86_64 (mimvp-sz2) 12/13/2019 _x86_64_ (2 CPU) 10:58:58 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 10:58:59 PM eth0 6.00 4.00 0.58 0.57 0.00 0.00 0.00 10:58:59 PM lo 71.00 71.00 1559.42 1559.42 0.00 0.00 0.00 10:58:59 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 10:59:00 PM eth0 9.00 8.00 0.71 2.60 0.00 0.00 0.00 10:59:00 PM lo 65.00 65.00 79.55 79.55 0.00 0.00 0.00 10:59:00 PM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 10:59:01 PM eth0 10.00 10.00 1.90 7.83 0.00 0.00 0.00 10:59:01 PM lo 125.00 125.00 1618.70 1618.70 0.00 0.00 0.00 Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s Average: eth0 8.33 7.33 1.06 3.67 0.00 0.00 0.00 Average: lo 87.00 87.00 1085.89 1085.89 0.00 0.00 0.00
2、IPTraf
IPTraf 功能很强大,可以监控所有的流量,IP流量,按协议分的流量,还可以设置过滤器等
Github:https://github.com/iptraf-ng/iptraf-ng
CentOS 系统yum方式安装:sudo yum install iptraf-ng
Ubuntu 系统apt方式安装:sudo apt-get install iptraf-ng
安装完成后直接运行 sudo iptraf ,有菜单提示进入相应功能
Shell 脚本方式,通过ifconfig命令获取tx,rx数据,被动获取
此文中ifconfig格式跟 CentOS 不一样,CentOS 需要调整取数据部分
#!/bin/bash # # shaozx@gmail.com 2010-10-19 # # Usage: # ./netspeed.sh runs 60 seconds by step 1s, default to eth0 # ./netspeed.sh eth1 10 runs 10 seconds by step 1s, default to eth1 # ./netspeed.sh eth1 90 5 runs 90 seconds by step 5s, default to eth1 IF="eth0" # net card device TIME=60 # run $TIME seconds before quit STEP=1 # wait $STEP seconds IFCONF="/sbin/ifconfig" [ ! -x "/sbin/ifconfig" ] && IFCONF=`type ifconfig | awk '{print $NF}' | sed 's/(\|)//g'` [ "$1" != "" ] && IF=$1 [ "$2" != "" ] && TIME=$2 [ "$3" != "" ] && STEP=$3 ## ========================================= ## ## DO NOT NEED CHANGE ## ## ========================================= ## export LC_ALL=C show_sum() { #printf "\n%s\n" "[`date +'%Y-%m-%d %H:%M:%S'`](END)" echo echo #printf "%d seconds,\n" $RUN #printf "rx from %d to %d\n" $RX_I $RX #printf "tx from %d to %d\n" $TX_I $TX echo '-----------------------------------' printf "| | TOTAL(K) | AVG(K/S) |\n" echo '|---------------------------------|' printf "|RX |%12d |%10d | runs %d seconds\n" \ $(( (RX-RX_I)/1024 )) $(( (RX-RX_I)/1024/$RUN )) \ $RUN printf '|---------------------------------| rx from %d to %d\n' \ $RX_I $RX printf "|TX |%12d |%10d | tx from %d to %d\n" \ $(( (TX-TX_I)/1024 )) $(( (TX-TX_I)/1024/$RUN )) \ $TX_I $TX echo '-----------------------------------' exit 0 } trap show_sum INT # stty intr ^C TX_OLD=0 RX_OLD=0 echo echo " IF: $IF TIME: ${TIME}s (step=${STEP}s) (down/up)" echo '----------------------------------------------------------' while [ 1 ] do LINE=`$IFCONF $IF | grep "TX bytes"` RX=`echo $LINE | cut -d: -f2 | awk '{print $1}'` TX=`echo $LINE | cut -d: -f3 | awk '{print $1}'` if [ $TX_OLD -eq 0 -a $RX_OLD -eq 0 ] then RX_I=$RX; TX_I=$TX; RX_OLD=$RX; TX_OLD=$TX; RUN=0 sleep $STEP continue fi RUN=$((RUN+STEP)) if [ $RUN -ge $TIME ] then show_sum break fi RX_SUB=`expr $RX - $RX_OLD` TX_SUB=`expr $TX - $TX_OLD` RX_SUB=`expr $RX_SUB / $STEP / 1024` TX_SUB=`expr $TX_SUB / $STEP / 1024` RX_OLD=$RX TX_OLD=$TX printf "%s%-10s" "[`date +'%Y-%m-%d %H:%M:%S'`]" "($((TIME-RUN)))" printf "%10d%10d (K/S)\n" $RX_SUB $TX_SUB sleep $STEP done
使用方法:
sh netspeed.sh runs 60 seconds by step 1s, default to eth0 sh netspeed.sh eth1 10 runs 10 seconds by step 1s, default to eth1 sh netspeed.sh eth1 90 5 runs 90 seconds by step 5s, default to eth1
使用 Linux C 语言获取当前网速
vim test_network_speed.c
/***************************************************** * * 作者:杨志永 * 日期:2012-4-16 4:35PM * E-mail:ljy520zhiyong@163.com * QQ:929168233 * * filename: test_network_speed.c * 编译环境:Debian 6.0.4 Testing + GCC 4.6.3 X86_64 * *****************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define WAIT_SECOND 3 //暂停时间,单位为“秒” long int getCurrentDownloadRates(long int * save_rate); //获取当前的流量,参数为将获取到的流量保存的位置 int main(int argc, char * argv[]) { long int start_download_rates; //保存开始时的流量计数 long int end_download_rates; //保存结果时的流量计数 while(1) { getCurrentDownloadRates(&start_download_rates);//获取当前流量,并保存在start_download_rates里 sleep(WAIT_SECOND); //休眠多少秒,这个值根据宏定义中的WAIT_SECOND的值来确定 //sleep的头文件在unistd.h getCurrentDownloadRates(&end_download_rates);//获取当前流量,并保存在end_download_rates里 printf("download is : %.2lf Bytes/s\n", (float)(end_download_rates-start_download_rates)/WAIT_SECOND );//打印结果 } exit(EXIT_SUCCESS); } long int getCurrentDownloadRates(long int * save_rate) { FILE * net_dev_file; //文件指针 char buffer[1024]; //文件中的内容暂存在字符缓冲区里 size_t bytes_read; //实际读取的内容大小 char * match; //用以保存所匹配字符串及之后的内容 if ( (net_dev_file=fopen("/proc/net/dev", "r")) == NULL ) //打开文件/pro/net/dev/,我们要读取的数据就是它啦 { printf("open file /proc/net/dev/ error!\n"); exit(EXIT_FAILURE); } bytes_read = fread(buffer, 1, sizeof(buffer), net_dev_file);//将文件中的1024个字符大小的数据保存到buffer里 fclose(net_dev_file); //关闭文件 if ( bytes_read == 0 )//如果文件内容大小为0,没有数据则退出 { exit(EXIT_FAILURE); } buffer[bytes_read] = '\0'; match = strstr(buffer, "eth0:");//匹配eth0第一次出现的位置,返回值为第一次出现的位置的地址 if ( match == NULL ) { printf("no eth0 keyword to find!\n"); exit(EXIT_FAILURE); } sscanf(match, "eth0:%ld", save_rate);//从字符缓冲里读取数据,这个值就是当前的流量啦。呵呵。 return *save_rate;
其它测速工具
参考推荐:
Linux 实用好评的命令工具 (推荐)
Linux free命令:buffer 与 cache 区别
Web网页性能压测工具 ApacheBench 和 WebBench
Linux 修改默认端口、增加普通用户、使用密钥等安全登录SSH
Linux shell 脚本通过expect实现自动输入密码
Linux之/etc/profile、~/.bash_profile等几个文件的执行过程
nohup、&、disown、setsid、screen、jobs 后台运行命令区别
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2020-01-31 05:00:35
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!