| MdbAddr = "\\win-pc\vbs\1.mdb" |
| Miaoshu = 1 |
| Shijian = Miaoshu*1000 |
| |
| |
| Dim WMI |
| |
| Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") |
| |
| |
| |
| |
| Set colComputers = WMI.ExecQuery("Select * from Win32_ComputerSystem") |
| For Each objComputer in colComputers |
| PcName = objComputer.Name |
| Exit For |
| Next |
| |
| |
| Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'") |
| For Each objItem In colItems |
| NetName = Replace(objItem.Description,"/","_") |
| MacAddr = objItem.MacAddress |
| For Each objAddress in objItem.IPAddress |
| If objAddress <> "" then |
| IpAddr = objAddress |
| Exit For |
| End If |
| Next |
| Next |
| Set colItems = Nothing |
| UserName= CreateObject("wscript.network").username |
| |
| |
| |
| Call Network(Name) |
| |
| Function Network(Names) |
| |
| If CreateObject("Scripting.FileSystemObject").FileExists(MdbAddr) Then |
| |
| Else |
| |
| |
| CreateObject("ADOX.Catalog").Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & MDBaddr |
| |
| Set connObj = CreateObject("ADODB.Connection") |
| connObj.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & MdbAddr |
| connObj.Execute "CREATE TABLE Speed(计算机名 varchar(255),用户名 varchar(255),IP地址 varchar(255),下载速度 varchar(255),上传速度 varchar(255),时间 varchar(255),MAC地址 varchar(255),网卡名称 varchar(255))" |
| connObj.Close |
| Set connObj = Nothing |
| End If |
| |
| Do |
| Dim A |
| Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& NetName &"'") |
| 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(Shijian) |
| Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& NetName &"'") |
| For Each B In A |
| R2 = B.BytesReceivedPersec |
| S2 = B.BytesSentPersec |
| T2 = B.BytesTotalPersec |
| Next |
| Set A = Nothing |
| Down=CheckSize((R2-R1)/Miaoshu) &"/s" |
| Up=CheckSize((S2-S1)/Miaoshu) &"/s" |
| |
| |
| Dim rsObj |
| Set connObj = CreateObject("ADODB.Connection") |
| connObj.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & MdbAddr |
| connObj.Open |
| Set rsObj = CreateObject("ADODB.RecordSet") |
| rsObj.Open "select * FROM Speed where MAC地址 = '"& MacAddr & "'", connObj, 1, 3 |
| If Not rsObj.Eof Then |
| |
| rsObj("计算机名") = pcname |
| rsObj("用户名") = username |
| rsObj("IP地址") = ipaddr |
| rsObj("下载速度") = down |
| rsObj("上传速度") = up |
| rsObj("时间") = Now() |
| rsObj.Update |
| rsObj.Close |
| connObj.Close |
| Else |
| |
| rsObj.Close |
| connObj.Close |
| connObj.open |
| rsObj.Open "select * FROM Speed", connObj, 1, 3 |
| rsObj.AddNew |
| If Not rsObj.Eof Then |
| rsObj("计算机名") = PcName |
| rsObj("用户名") = UserName |
| rsObj("IP地址") = IpAddr |
| rsObj("下载速度") = Down |
| rsObj("上传速度") = Up |
| rsObj("时间") = Now() |
| rsObj("MAC地址") = MacAddr |
| rsObj("网卡名称") = NetName |
| rsObj.Update |
| rsObj.Close |
| connObj.Close |
| End If |
| End If |
| Set rsObj = Nothing |
| Set connObj = Nothing |
| 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 & " B" |
| End If |
| CheckSize=Right(" " & SZ,10) |
| End FunctionCOPY |