多网卡流量统计实现:yu2n 2013-07-14 - ' 多网卡流量统计实现:yu2n 2013-07-14
-
- ' VBS统计网络流量 - fastslz 2009-1-28 23:07
- ' 如果你是包流量无线网卡,那这个脚本非常有用
- ' http://www.bathome.net/thread-3198-1-1.html
-
- ' *==============================================================================*
- ' * 网络流量统计.vbs By: FastSLZ 2009-1-28 首次发布与 bbs.bathome.cn *
- ' *==============================================================================*
- '特别提醒:本脚本必须在Administrator账户,且必须通过杀毒软件授权下才能正常运行!
-
-
- ' 以命令提示符环境运行
- Dim WH
- Set WH = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_DesktopMonitor")
- For Each aWH in WH
- TW = Int(aWH.ScreenWidth/8)
- Next
- Set WH = Nothing
- If TW <= 0 Then
- TW =128
- End If
- If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
- CreateObject("WScript.Shell").Run( _
- "%Comspec% /C " & Chr(34) & "mode con cols=" & TW & "&Title 网络流量统计 By: FastSLZ bbs.bathome.cn &&Cscript.exe //NoLogo " & _
- Chr(34) & Wscript.ScriptFullName & Chr(34) & Chr(34) ),3
- Wscript.Quit
- End If
-
- ' 提示信息
- Dim sTip
- sTip = "网络流量统计.vbs By: FastSLZ 2009-1-28 首次发布与 bbs.bathome.cn" & VbCrLf & _
- "小计:(脚本开始合计流量)" & VbCrLf & _
- "累计:(本次连接后的合计流量)" & VbCrLf
- WScript.Echo sTip
-
- ' 获取输入的检测间隔时间
- Showy= "本脚本用于检测BT等下载工具后台偷偷上传、下载,及检测是否存在潜伏在系统里的后门程序" & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
- Input=InputBox(Showy & "请输入刷新间隔时间(单位秒)" & vbCrLf & "间隔时间越长统计数据越精确", "BY: fastslz", "2")
- Input=Int(Input)
- If Len(Input) = 0 Then:Input = 1:End If
- If Len(Input) >= 2 Then:WScript.Quit:End If
- InputS = Input*1000
-
-
- ' 循环检测多块网卡
- Dim WMI,Name
- Dim objDict ' 字典(保存网卡的使用流量小记,多块网卡)
- Set objDict = CreateObject("Scripting.Dictionary")
- Do
- ' 取得活动的网卡名
- Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'")
- If colItems.Count = 0 Then
- MsgBox vbTab & "无网络连接!"
- Exit Do
- End If
- For Each objItem In colItems
- ' 读取网卡名
- Name = Replace(objItem.Description, "/", "_")
-
- ' 读取字典中保存的流量数据(脚本开启后使用的流量总计),即字典中保存的Name字段(网卡名)的值
- If objDict.Exists(Name) Then
- T0 = objDict.Item(Name)
- Else
- objDict.Add Name, T0
- End If
-
- ' 检测当前网络信息
- WScript.Echo "活动连接:" & Name
- Call Network(Name, T0)
-
- ' 更新流量小记(脚本开启后使用的流量总计)
- objDict.Item(Name) = T0
- Next
- Set colItems = Nothing
-
- WScript.Echo VbCrLf
- WScript.Sleep(InputS)
- Loop
-
-
- ' 检测当前网络信息
- Function Network(ByVal Names, ByRef T0)
-
- Dim A
- Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
- For Each B In A
- R1 = B.BytesReceivedPersec
- S1 = B.BytesSentPersec
- T1 = B.BytesTotalPersec
- If T0 ="" Then :T0 = B.BytesTotalPersec :End If
- Next
- Set A = Nothing
-
- WScript.Sleep(InputS)
-
- Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
- For Each B In A
- R2 = B.BytesReceivedPersec
- S2 = B.BytesSentPersec
- T2 = B.BytesTotalPersec
- Next
- Set A = Nothing
- WScript.Echo "下载:" & CheckSize((R2-R1)/Input) &"/s" _
- &vbTab&"上传:" & CheckSize((S2-S1)/Input) &"/s" _
- &vbTab&"平均:" & CheckSize((T2-T1)/Input) &"/s" _
- &vbTab&"小计:" & CheckSize(T1-T0) _
- &vbTab&"累计:" & CheckSize(T1)
-
- End Function
-
-
- ' 人性化网络流量单位格式
- Function CheckSize(ByVal SZ)
- On Error Resume Next
- If SZ => 1073741824 Then
- SZ = FormatNumber(SZ/1073741824) & " GB"
- ElseIf SZ => 1048576 Then
- SZ = FormatNumber(SZ/1048576) & " MB"
- ElseIf SZ => 1024 Then
- SZ = FormatNumber(SZ/1024) & " KB"
- Else
- SZ = SZ & " 字节"
- End If
- CheckSize=Right(" " & SZ,10)
- End Function
复制代码
|