lua帯域幅取得
#!/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)