Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wanted: Bytes Sent / Received

Status
Not open for further replies.

Trevil

Programmer
Jun 19, 2003
459
0
0
US
I would appreciate ANY code to provide network bytes sent and received from Performance Counters on a workstation (or is there another place?)

Thank you for your assistance.

"Have a great day today and a better day tomorrow!
 
Thank you for responding. I'm just getting my feet wet with .Net (have used VB6 for years), and I'm hoping to find a VB sample.

"Have a great day today and a better day tomorrow!
 
After much trial and error I finally figured out how to obtain the byte counts across the TCPIP connection(s). The following sample is provided in case some other poor soul needs a quick and dirty view.

Notes:
1. My workstation has three TCIP return values, but only the first one is what I want (last one never changes). Check the value in "objItem.Name".
2. There's a ton of other stats available, but I excluded from this sample. Let me know if you want additional data.

Public Type BytesSentReceived
BytesSent As Double
BytesReceived As Double
End Type

Sub Call_Sample()
Dim ByteCounts As BytesSentReceived
ByteCounts = Get_Bytes_Sent_Received
Debug.print "Sent: " & ByteCounts.BytesSent
Debug.print "Rcvd: " & ByteCounts.BytesReceived
End Sub

Function Get_Bytes_Sent_Received() As BytesSentReceived
Dim strComputer As String
Dim objWMIService
Dim colItems
Dim objItem
Dim ByteCounts As BytesSentReceived
'MsgBox "Get_Bytes_Sent_Received: find correct name to use..."
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface", , 48)
For Each objItem In colItems
If objItem.Name <> "MS TCP Loopback interface" Then
'Debug.Print "-------------Win32_PerfRawData_Tcpip_NetworkInterface---------- "
'Debug.Print "Name: " & objItem.Name
'Debug.Print "BytesReceivedPersec: " & objItem.BytesReceivedPersec
'Debug.Print "BytesSentPersec: " & objItem.BytesSentPersec
ByteCounts.BytesReceived = objItem.BytesReceivedPersec
ByteCounts.BytesSent = objItem.BytesSentPersec
End If
Next
Get_Bytes_Sent_Received = ByteCounts
Set objItem = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
End Function


"Have a great day today and a better day tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top