本帖最后由 czar8 于 2012-3-28 17:31 编辑
本人想在cmd中获取网络流量,再执行相应的操作,批处理后台反复执行。
找了半天只找到了下面这个VBS脚本,执行结果看上去不错,但本人对VBS纯属文盲。想把它的结果写到c:\rece.txt中,9秒刷新写入一次。希望大伙给予帮助,谢谢。- ' *==============================================================================*
- ' * 网络流量统计.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)
- Nexta
- 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 网络流量统计&&Cscript.exe //NoLogo "&Chr(34)& Wscript.ScriptFullName &Chr(34)&Chr(34)),3:Wscript.Quit
- End If
- Showy=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
- Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
-
- Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'")
- For Each objItem In colItems
- Name = Replace(objItem.Description,"/","_")
- Next
- Set colItems = Nothing
- WScript.Echo "活动连接:"&Name
- If (IsArray(Name)) = TRUE Then:MsgBox vbTab& "貌似无任何网络" :WScript.Quit:End If
- Call Network(Name)
- Function Network(Names)
- Do
- 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)
- Loop
- End Function
-
- Function CheckSize(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
复制代码
|