标题: [原创] VBS统计网络流量 [打印本页]
作者: fastslz 时间: 2009-1-28 23:07 标题: VBS统计网络流量
如果你是包流量无线网卡,那这个脚本非常有用- ' *==============================================================================*
- ' * 网络流量统计.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
- MsgBox "本脚本用于检测BT等下载工具后台偷偷上传、下载,及检测是否存在潜伏在系统里的后门程序"
- 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
复制代码
作者: BBCC 时间: 2009-1-28 23:25
伟大的wmi!
作者: fastslz 时间: 2011-4-30 20:59
2011-4-30 更新
小计:(脚本开始合计流量)
累计:(本次连接后的合计流量)
作者: kmcc123 时间: 2011-5-5 22:42
u = "http://www.baidu.com"
set objh = Createobject("MSXML2.XMLHTTP")
objh.open "GET",u,false
objh.send()
if objh.statustext = "OK" then msgbox "通" else msgbox "断"
作者: kmcc123 时间: 2011-5-5 22:45
想把上面的带码改成
代理服务器10.0.0.172 80的
如果通就是拨上WAP网
反之NET网
作者: lxzzr 时间: 2012-3-13 13:00
两个类得到的网络设备名称不一定一致,所以,对“Name = Replace(objItem.Description,"/","_")”这句觉得有点不妥....
作者: fastslz 时间: 2012-3-23 23:28
两个类得到的网络设备名称不一定一致,所以,对“Name = Replace(objItem.Description,"/","_")”这句觉得 ...
lxzzr 发表于 2012-3-13 13:00
原本没有这句的,加上确实觉得不妥,不加怕菜鸟级不知道如何选择,我也不知道如何取得一致的网络设备名,所以先只能这样了。
xzzr兄有什么办法吗?
作者: lxzzr 时间: 2012-3-25 20:13
回复 7# fastslz
我也没有好的办法,我选择的是流量最大的网卡,不过,你那个是流量统计,我觉得应该是所有网卡的流量和
作者: wodesitanfu 时间: 2012-8-3 15:33
请问,这种方法能计算到走UPD的流量吗
作者: wodesitanfu 时间: 2012-8-3 15:34
UDP,打错了
作者: yu2n 时间: 2013-7-14 21:04
多网卡流量统计实现: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
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |