1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#!/usr/bin/lua
local
socket = require(
"socket"
)
local
name = os.tmpname()
os.execute([[
ifconfig
|
head
-1 |
cut
-d
' '
-f1 >]]..name)
local
readName = io.
open
(name,
"r"
)
local
realName = readName:
read
(
"*l"
)
local
file
= io.
open
(
"/sys/class/net/"
..realName..
"/statistics/tx_bytes"
,
"r"
)
local
tx1 =
file
:
read
(
"*l"
)
socket.
sleep
(1)
file
:seek(
"set"
)
local
tx2 =
file
:
read
(
"*l"
)
local
mb = (tx2-tx1)*8
/1024/1024
print(math.ceil(mb)..
"Mbps"
)
file
:close()
readName:close()
os.remove(name)
|
本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1392498,如需转载请自行联系原作者