Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function GetNetworkData
'Clear total counters
TotalBytesReceivedPerSec = 0
TotalBytesSentPerSec = 0
TotalBytesTotalPerSec = 0
TotalPacketsReceivedPerSec = 0
TotalPacketsSentPerSec = 0
TotalPacketsReceivedDiscarded = 0
TotalPacketsReceivedError = 0
TotalPacketsSentDiscarded = 0
Set colNetAdapters = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter") ' WHERE Caption = '" & objConf.Caption & "'")
For Each objAdapter In colNetAdapters
strAdapterName = GetAdapterName(objAdapter.Name)
'Handle the bandwidth and bytes counters
MonitorName = "Bytes Throughput: " + objAdapter.NetConnectionID
MonitorID = FindMonitorID(MonitorName)
If Trim(MonitorID) <> "" Then
For Each objItem in objNetworkData
strPerfDataName = GetAdapterName(objItem.Name)
WScript.Echo strPerfDataName & " - " & GetAdapterName(objItem.Name)
If strPerfDataName = strAdapterName Then
Wscript.echo "Name: " & strPerfDataName
Wscript.Echo "Bytes Received/Sec: " & objItem.BytesReceivedPersec
Wscript.Echo "Bytes Sent/Sec: " & objItem.BytesSentPersec
Wscript.Echo "Bytes Total/Sec: " & objItem.BytesTotalPersec
Results = "BytesTotalPerSec:" & CStr(objItem.BytesTotalPerSec) & _
";BytesReceivedPerSec:" & CStr(objItem.BytesReceivedPerSec) & _
";BytesSentPerSec:" & CStr(objItem.BytesSentPerSec)
AddResult
'Accumulate Totals
TotalBytesReceivedPerSec = TotalBytesReceivedPerSec + objItem.BytesReceivedPerSec
TotalBytesSentPerSec = TotalBytesSentPerSec + objItem.BytesSentPerSec
TotalBytesTotalPerSec = TotalBytesTotalPerSec + objItem.BytesTotalPerSec
End If
Next
End If
'Handle the packet counters
MonitorName = "Packets: " & objAdapter.NetConnectionID
MonitorID = FindMonitorID(MonitorName)
If Trim(MonitorID) <> "" Then
For Each objItem in objNetworkData
strPerfDataName = GetAdapterName(objItem.Name)
WScript.Echo strPerfDataName & " - " & GetAdapterName(objItem.Name)
If strPerfDataName = strAdapterName Then
Wscript.echo "Name: " & strPerfDataName
Wscript.Echo "Packets Received/Sec: " & objItem.PacketsReceivedPersec
Wscript.Echo "Packets Sent/Sec : " & objItem.PacketsSentPersec
Results = "PacketsReceivedPerSec:" & CStr(objItem.PacketsReceivedPersec) & _
";PacketsSentPerSec:" & CStr(objItem.PacketsSentPersec) & _
";PacketsReceivedDiscarded:" & CStr(objItem.PacketsReceivedDiscarded) & _
";PacketsReceivedError:" & CStr(objItem.PacketsReceivedErrors) & _
";TotalPacketsPerSec:" & CStr(objItem.PacketsPerSec)
AddResult
'Accumulate Totals
TotalPacketsReceivedPerSec = TotalPacketsReceivedPerSec + objItem.PacketsReceivedPersec
TotalPacketsSentPerSec = TotalPacketsSentPerSec + objItem.PacketsSentPersec
TotalPacketsReceivedDiscarded = TotalPacketsReceivedDiscarded + objItem.PacketsReceivedDiscarded
TotalPacketsReceivedError = TotalPacketsReceivedError + objItem.PacketsReceivedErrors
TotalPacketsPerSec = TotalPacketsPerSec + objItem.PacketsPerSec
End If
Next
End If
Next
'Add Total results to the monitor
MonitorName = "Total Bytes Throughput"
MonitorID = FindMonitorID(MonitorName)
If Trim(MonitorID) <> "" Then
Results = "TotalBytesTotalPerSec:" & CStr(TotalBytesTotalPerSec) & _
";TotalBytesReceivedPerSec:" & CStr(TotalBytesReceivedPerSec) & _
";TotalBytesSentPerSec:" & CStr(TotalBytesSentPerSec)
AddResult
End If
MonitorName = "Total Packets"
MonitorID = FindMonitorID(MonitorName)
If Trim(MonitorID) <> "" Then
Results = "TotalPacketsReceived:" & CStr(TotalPacketsReceivedPerSec) & _
";TotalPacketsSent:" & CStr(TotalPacketsSentPerSec) & _
";TotalPacketsReceivedDiscarded:" & CStr(TotalPacketsReceivedDiscarded) & _
";TotalPacketsReceivedErrors:" & CStr(TotalPacketsReceivedError) & _
";TotalPacketsPerSec:" & CStr(TotalPacketsPerSec)
AddResult
End If
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.