终端下显示网速的SHELL脚本
时间:2007-06-16 来源:dorainm
( framebuffer: 喂, 我可以让你在字符界面看电影的... )
我几乎用不到X, 而且X20的配置, 开X有点虚...
more /proc/cpuifon ; free ; df ; top
可以看一些系统的状况, 比如CPU信息, 内存, 硬盘, 进程...
但是dorainm一直没有找到一款能即时显示网速的
比如 eth0上传 xx KB/S
虽然 /sbin/ifconfig 可以查看网络状态
毛主席告诉我们, 自动动手, 丰衣足食
因为 /sbin/ifconfig 里面有条信息,
告诉我们当前某个连接的总数据量 total bytes
如果我们每1秒钟去获取这个total bytes
然后把两次结果相减, 不就可以获得 xx B/S的网络速度了吗??
当然, 这个数字也会一时无法直观表示,
比如当这数字大于 1024时候, 就转化为 KB/S 的单位
如果数字大于 1024*1024, 就转化为 MB/S
... ...
这样子结果就比较直观了
okay, let's go
rate程序写了有一年了吧, google了好多拼凑出来的
代码很难阅读, 本来想什么时候优化一下, 发布出来
但是一直没有做, 今天决定还是拿出来让需要的群众来使用吧
运行
$ rate --help usage : /home/dorainm/bin/rate [DEV_NAME] [ TIMES | -t ] DEV_NAME the name of the network device, default: eth0 TIMES the times of counts, default: 1 -t counting until break $ |
比如查看 lo 1次( 1秒钟 ) 的网络速度
$ rate lo the Rate of Network, by dorainm, [email protected] ----------------------------------------------------- RX Rate = 767 B/S Totle Bytes : 8.182 TX Rate = 767 B/S Totle Bytes : 8.182 ----------------------------------------------------- All Done $ |
下面看持续观看 eth0 的网络速度
$ rate -t the Rate of Network, by dorainm, [email protected] ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.710 MB TX Rate = 0 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.710 MB TX Rate = 0 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 60 B/S Totle Bytes : 40.710 MB TX Rate = 66 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 154 B/S Totle Bytes : 40.710 MB TX Rate = 146 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.710 MB TX Rate = 0 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 71 B/S Totle Bytes : 40.710 MB TX Rate = 137 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.710 MB TX Rate = 0 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 140 B/S Totle Bytes : 40.710 MB TX Rate = 156 B/S Totle Bytes : 30.908 MB ----------------------------------------------------- RX Rate = 1.343 KB/S Totle Bytes : 40.712 MB TX Rate = 707 B/S Totle Bytes : 30.909 MB ----------------------------------------------------- RX Rate = 757 B/S Totle Bytes : 40.713 MB TX Rate = 564 B/S Totle Bytes : 30.910 MB ----------------------------------------------------- RX Rate = 370 B/S Totle Bytes : 40.713 MB TX Rate = 263 B/S Totle Bytes : 30.910 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.713 MB TX Rate = 0 B/S Totle Bytes : 30.910 MB ----------------------------------------------------- RX Rate = 256 B/S Totle Bytes : 40.713 MB TX Rate = 619 B/S Totle Bytes : 30.910 MB ----------------------------------------------------- RX Rate = 6.039 KB/S Totle Bytes : 40.719 MB TX Rate = 354 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.719 MB TX Rate = 0 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 1.470 KB/S Totle Bytes : 40.720 MB TX Rate = 210 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 66 B/S Totle Bytes : 40.721 MB TX Rate = 0 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.721 MB TX Rate = 0 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.721 MB TX Rate = 0 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.721 MB TX Rate = 0 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 370 B/S Totle Bytes : 40.721 MB TX Rate = 366 B/S Totle Bytes : 30.911 MB ----------------------------------------------------- RX Rate = 1.417 KB/S Totle Bytes : 40.722 MB TX Rate = 430 B/S Totle Bytes : 30.912 MB ----------------------------------------------------- RX Rate = 405 B/S Totle Bytes : 40.723 MB TX Rate = 66 B/S Totle Bytes : 30.918 MB ----------------------------------------------------- RX Rate = 60 B/S Totle Bytes : 40.723 MB TX Rate = 128 B/S Totle Bytes : 30.918 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.723 MB TX Rate = 152 B/S Totle Bytes : 30.919 MB ----------------------------------------------------- RX Rate = 74 B/S Totle Bytes : 40.724 MB TX Rate = 614 B/S Totle Bytes : 30.919 MB ----------------------------------------------------- RX Rate = 5.904 KB/S Totle Bytes : 40.729 MB TX Rate = 300 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 1.535 KB/S Totle Bytes : 40.731 MB TX Rate = 210 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 140 B/S Totle Bytes : 40.731 MB TX Rate = 156 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 230 B/S Totle Bytes : 40.731 MB TX Rate = 210 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.731 MB TX Rate = 0 B/S Totle Bytes : 30.920 MB ----------------------------------------------------- RX Rate = 1.595 KB/S Totle Bytes : 40.733 MB TX Rate = 582 B/S Totle Bytes : 30.921 MB ----------------------------------------------------- RX Rate = 60.839 KB/S Totle Bytes : 40.792 MB TX Rate = 2.443 MB/S Totle Bytes : 33.364 MB ----------------------------------------------------- RX Rate = 0 B/S Totle Bytes : 40.792 MB TX Rate = 0 B/S Totle Bytes : 33.364 MB ----------------------------------------------------- RX Rate = 74 B/S Totle Bytes : 40.792 MB TX Rate = 615 B/S Totle Bytes : 33.365 MB ----------------------------------------------------- RX Rate = 7.312 KB/S Totle Bytes : 40.799 MB TX Rate = 408 B/S Totle Bytes : 33.365 MB ----------------------------------------------------- ^c $ |
附rate源码
#!/bin/bash |