다음 코드는, 2초 간격으로 네트워크 인터페이스를 통해서 발생하는 트래픽을 모니터링 하는 코드이다.
Windows Server 2003 및 XP에 서만 체크가 가능하다.
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colItems = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_TCPIP_NetworkInterface").objectSet
objRefresher.Refresh
For i = 1 to 5
For Each objItem in colItems
Wscript.Echo "Bytes Received Per Second: " & _
objItem.BytesReceivedPersec
Wscript.Echo "Bytes Sent Per Second: " & objItem.BytesSentPersec
Wscript.Echo "Bytes Total Per Second: " & objItem.BytesTotalPersec
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Current Bandwidth: " & objItem.CurrentBandwidth
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Output Queue Length: " & objItem.OutputQueueLength
Wscript.Echo "Packets Outbound Discarded: " & _
objItem.PacketsOutboundDiscarded
Wscript.Echo "Packets Outbound Errors: " & _
objItem.PacketsOutboundErrors
Wscript.Echo "Packets Per Second: " & objItem.PacketsPersec
Wscript.Echo "Packets Received Discarded: " & _
objItem.PacketsReceivedDiscarded
Wscript.Echo "Packets Received Errors: " & _
objItem.PacketsReceivedErrors
Wscript.Echo "Packets Received Non-Unicast Per Second: " & _
objItem.PacketsReceivedNonUnicastPersec
Wscript.Echo "Packets Received Per Second: " & _
objItem.PacketsReceivedPersec
Wscript.Echo "Packets Received Unicast Per Second: " & _
objItem.PacketsReceivedUnicastPersec
Wscript.Echo "Packets Received Unknown: " & _
objItem.PacketsReceivedUnknown
Wscript.Echo "Packets Sent Non-Unicast Per Second: " & _
objItem.PacketsSentNonUnicastPersec
Wscript.Echo "Packets Sent Per Second: " & objItem.PacketsSentPersec
Wscript.Echo "Packets Sent Unicast Per Second: " & _
objItem.PacketsSentUnicastPersec
Wscript.Sleep 2000
objRefresher.Refresh
Next
Next
만약 Windows 2000 환경이라면,
다음과 같이 성능카운터의 원시데이터를 이용해서 계산을 해줘야 한다.
'카드 이름에서, ()문자열은 []로 변경해야하며, / 문자는 _ 로 변경해야 함.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface WHERE Name = '"& NetworkCardName &"'")
For Each objItem In colItems
'WScript.Echo "BytesSentPersec: " & objItem.BytesSentPersec
D1 = objItem.BytesSentPersec
Next
WScript.Sleep(1000)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface WHERE Name = '"& NetworkCardName &"'")
For Each objItem In colItems
'WScript.Echo "BytesSentPersec: " & objItem.BytesSentPersec
D2 = objItem.BytesSentPersec
Next
WScript.Echo "Total Bytes/s=" & D2-D1
댓글 없음:
댓글 쓰기