Status Lan connection - bytes send / recieved

G

Guest

Use PerformanceCounter class. Set CategoryName to "Network Interface" and
select "Bytes Received/sec" etc.

Hope this helps
 
N

newbie

But that counter is per second.
How do I know what is send sinds the reboot ?
Or where can I find the elapsed seconds ? So I can multiply it with the
counter bytes/sec.
 
G

Guest

If you don't want per sec use RawValue. "Network connection status" and "Task
Manager" display raw value of the "Packets Received Unicast" preformance
counter( well almost - i dont know why "Network connection status" shows
different value for the total packet sent, but the same for received)

Hope this helps
 
N

newbie

You are pointing to this?

VB.NET code:

Try

Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT
BytesReceivedPersec,BytesSentPersec,BytesTotalPersec FROM
Win32_PerfRawData_Tcpip_NetworkInterface")
Dim totaalverzonden, totaalontvangen, totaal As Int64

For Each queryObj As ManagementObject In searcher.Get()
totaalontvangen = totaalontvangen +
Convert.ToInt64(queryObj("BytesReceivedPersec"))
totaalverzonden = totaalverzonden +
Convert.ToInt64(queryObj("BytesSentPersec"))
totaal += Convert.ToInt64(queryObj("BytesTotalPersec"))
Next

Console.WriteLine("Totaalontvangen: " & totaalontvangen.ToString)
Console.WriteLine("Totaalverzonden: " & totaalverzonden.ToString)
Console.WriteLine("Totaal: " & totaal.ToString)

Catch err As ManagementException
Console.WriteLine("An error occurred while querying for WMI data: " &
err.Message)
End Try



I thought, yess I have finally found it . But the value resets(<-- I tink it
resets) around 5,5 GB.
 
G

Guest

Put PerformanceCounter control on your form

Me.performanceCounter1.CategoryName = "Network Interface"
Me.performanceCounter1.CounterName = "Packets Received Unicast/sec"
Me.performanceCounter1.InstanceName = "Intel[R] PRO_100 VE Network
Connection - Packet Scheduler Miniport" ' it should be your ethernet device

dim lCounter as Long = performanceCounter1.NextSample().RawValue

I havent had this "around 5GB reset" problem yet :]
 
N

newbie

Ok idd, much easyer.

But I have still the problem. The performancecounter give you the amound of
bytes send / recieved during the past second.
I would like to know, how much bytes he has send / recieved since the
reboot.

http://www.aswin.be/nictransfer.JPG --> like that.

the rawvalue gives me idd a value wich is'nt 0 a values that increes.
But it isn't the same as in the jpg.
Do I have to calculate with the rawdata to get the actual bytes send and
recieved ?




Milosz Skalecki said:
Put PerformanceCounter control on your form

Me.performanceCounter1.CategoryName = "Network Interface"
Me.performanceCounter1.CounterName = "Packets Received Unicast/sec"
Me.performanceCounter1.InstanceName = "Intel[R] PRO_100 VE Network
Connection - Packet Scheduler Miniport" ' it should be your ethernet
device

dim lCounter as Long = performanceCounter1.NextSample().RawValue

I havent had this "around 5GB reset" problem yet :]
--
Milosz Skalecki
MCP, MCAD


newbie said:
can you give a little example ?
What about the reset of the value around 5GB ?
 
G

Guest

Sorry, I didn't see you have 'bytes' as unit in you Lan Status Dialog (I
reckon it's possible to change it to packets somwhere i.e. updating you
system). You can use 'Bytes received/sec' 'Bytes sent/sec' and then read
RawValue. A number you get matches to value that may be seen in 'Task
Manager->Networking' and 'netstat -e' console application. I don't know why
Lan Status bytes 'received' value differs from Performance couter equivalent.
Maybe there is an additional logic applied in 'Lan Status' program and i also
think it's driver related value (?). You can also use Win API (see WINAPI SDK
for GetIfTable, GetIfEntry) to get these values, but i'm pretty sure
Performance counter uses these functions internally (if you try it you'll see
all values are exactly the same as those returned by performance couter).

--
Milosz Skalecki
MCP, MCAD


newbie said:
Ok idd, much easyer.

But I have still the problem. The performancecounter give you the amound of
bytes send / recieved during the past second.
I would like to know, how much bytes he has send / recieved since the
reboot.

http://www.aswin.be/nictransfer.JPG --> like that.

the rawvalue gives me idd a value wich is'nt 0 a values that increes.
But it isn't the same as in the jpg.
Do I have to calculate with the rawdata to get the actual bytes send and
recieved ?




Milosz Skalecki said:
Put PerformanceCounter control on your form

Me.performanceCounter1.CategoryName = "Network Interface"
Me.performanceCounter1.CounterName = "Packets Received Unicast/sec"
Me.performanceCounter1.InstanceName = "Intel[R] PRO_100 VE Network
Connection - Packet Scheduler Miniport" ' it should be your ethernet
device

dim lCounter as Long = performanceCounter1.NextSample().RawValue

I havent had this "around 5GB reset" problem yet :]
--
Milosz Skalecki
MCP, MCAD


newbie said:
can you give a little example ?
What about the reset of the value around 5GB ?


"Milosz Skalecki" <[email protected]> schreef in bericht
Yep,

You can use easier approach performanceCounter.NextSample().RawValue

--
Milosz Skalecki
MCP, MCAD


:

You are pointing to this?

VB.NET code:

Try

Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT
BytesReceivedPersec,BytesSentPersec,BytesTotalPersec FROM
Win32_PerfRawData_Tcpip_NetworkInterface")
Dim totaalverzonden, totaalontvangen, totaal As Int64

For Each queryObj As ManagementObject In searcher.Get()
totaalontvangen = totaalontvangen +
Convert.ToInt64(queryObj("BytesReceivedPersec"))
totaalverzonden = totaalverzonden +
Convert.ToInt64(queryObj("BytesSentPersec"))
totaal += Convert.ToInt64(queryObj("BytesTotalPersec"))
Next

Console.WriteLine("Totaalontvangen: " & totaalontvangen.ToString)
Console.WriteLine("Totaalverzonden: " & totaalverzonden.ToString)
Console.WriteLine("Totaal: " & totaal.ToString)

Catch err As ManagementException
Console.WriteLine("An error occurred while querying for WMI data:
" &
err.Message)
End Try



I thought, yess I have finally found it . But the value resets(<-- I
tink
it
resets) around 5,5 GB.





"Milosz Skalecki" <[email protected]> schreef in bericht
If you don't want per sec use RawValue. "Network connection status"
and
"Task
Manager" display raw value of the "Packets Received Unicast"
preformance
counter( well almost - i dont know why "Network connection status"
shows
different value for the total packet sent, but the same for
received)

Hope this helps

--
Milosz Skalecki
MCP, MCAD


:

But that counter is per second.
How do I know what is send sinds the reboot ?
Or where can I find the elapsed seconds ? So I can multiply it with
the
counter bytes/sec.


"Milosz Skalecki" <[email protected]> schreef in bericht
Use PerformanceCounter class. Set CategoryName to "Network
Interface"
and
select "Bytes Received/sec" etc.

Hope this helps
--
Milosz Skalecki
MCP, MCAD


:

Hi all,

http://www.aswin.be/nictransfer.JPG
How can I get these numbers with VB.NET ?

I thought somewhere in WMI but I can't find them.

Thank you,
Aswin
 
N

newbie

ok thank you. I have tryed with some examples. But most examples that I can
find are VB6.0 / C
the code you gaved me is VB.NET but it doesn't work well.
It doesn't give all network interfaces / or don't give any interfaces .
On some computers it works / on others ... nothing.

but getiftable ... that's the thing I need.

Can you help me once again ?

thank you
 
G

Guest

-- BEGIN CODE --

Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class IpApi

Public Const MAX_INTERFACE_NAME_LEN As Integer = 256
Public Const MAXLEN_PHYSADDR As Integer = 8
Public Const MAXLEN_IFDESCR As Integer = 256
Public Const NO_ERROR As Integer = 0
Public Const ERROR_INSUFFICIENT_BUFFER As Integer = 122

<DllImport("iphlpapi.dll", SetLastError:=True)> _
Public Shared Function GetIfTable( _
ByVal pIfTable As IntPtr, _
ByRef pdwSize As UInt32, _
ByVal bOrder As Boolean) As Integer
End Function

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> Public
Structure MIB_IFROW
<MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=MAX_INTERFACE_NAME_LEN)> Public wszName As String
Public dwIndex As UInt32
Public dwType As UInt32
Public dwMtu As UInt32
Public dwSpeed As UInt32
Public dwPhysAddrLen As UInt32
<MarshalAs(UnmanagedType.ByValArray, sizeconst:=MAXLEN_PHYSADDR)>
Public bPhysAddr() As Byte
Public dwAdminStatus As UInt32
Public dwOperStatus As UInt32
Public dwLastChange As UInt32
Public dwInOctets As UInt32
Public dwInUcastPkts As UInt32
Public dwInNUcastPkts As UInt32
Public dwInDiscards As UInt32
Public dwInErrors As UInt32
Public dwInUnknownProtos As UInt32
Public dwOutOctets As UInt32
Public dwOutUcastPkts As UInt32
Public dwOutNUcastPkts As UInt32
Public dwOutDiscards As UInt32
Public dwOutErrors As UInt32
Public dwOutQLen As UInt32
Public dwDescrLen As UInt32
<MarshalAs(UnmanagedType.ByValArray, sizeconst:=MAXLEN_IFDESCR)>
Public bDescr() As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure MIB_IFTABLE
Public dwNumEntries As UInt32
Public table() As MIB_IFROW
End Structure

Public Shared Sub EnumerateInterfaces()

Dim size As UInt32
Dim result As Integer = 0
Dim buffer As IntPtr = IntPtr.Zero

result = GetIfTable(IntPtr.Zero, size, False)

Try

If (result = ERROR_INSUFFICIENT_BUFFER) Then
buffer = Marshal.AllocHGlobal(Convert.ToInt32(size))
result = GetIfTable(buffer, size, False)
Else
Throw New System.ComponentModel.Win32Exception(result)
End If

If (result <> NO_ERROR) Then
Throw New System.ComponentModel.Win32Exception(result)
Else

Dim count As Integer = Marshal.ReadInt32(buffer)
Dim ptr As Integer = buffer.ToInt32() +
Marshal.SizeOf(GetType(Integer))
Dim ifRow As MIB_IFROW
Dim description As String

For i As Integer = 1 To count
ifRow = CType(Marshal.PtrToStructure(New IntPtr(ptr),
GetType(MIB_IFROW)), MIB_IFROW)
description =
System.Text.Encoding.ASCII.GetString(ifRow.bDescr)
ptr += Marshal.SizeOf(GetType(MIB_IFROW))
Next

End If

Catch ex As Exception
Throw ex
Finally
If buffer.ToInt32() <> 0 Then
Marshal.FreeHGlobal(buffer)
End If
End Try

End Sub

End Class

-- END CODE --

Hope this helps
 
G

Guest

Sorry but I didn't have time to finish it. It's an example how to implement
it and i'm pretty sure you can proceed from this point yourself.
 
N

newbie

Hi,

I've found it to use your class. the enumerate subroutine..
the for i to count ... there I was able to find all the information I
want..
But, :-( he says in 4GB . Its inpossible because MSTCP loopback is 3,4GB.
+ only 1 GB out ?
server is online for 10days now. I guess he has send and recieved more then
20 GB .
console output from program:

Intel(R) PRO/1000 MT Desktop Adapter
inunpackets: 83.970.949 outunpackets: 51.885.545
inbytes: 4.092.707.942 outbytes: 999.628.193

MS TCP Loopback interface
inunpackets: 16.793.738 outunpackets: 16.779.370
inbytes: 3.428.810.751 outbytes: 3.428.810.751


And with you ?
If you send more then 10GB . The numbers are still correct ?

the subroutine enumeratinterfaces in your class, I have edited a little so
it outputs the info to the console.
your class:

Imports System.Reflection
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
IpApi.EnumerateInterfaces()
Console.ReadLine()
End Sub

Public Class IpApi

.......................

See other post

.......................

Public Shared Sub EnumerateInterfaces()

Dim size As UInt32

Dim result As Integer = 0

Dim buffer As IntPtr = IntPtr.Zero

result = GetIfTable(IntPtr.Zero, size, False)

Try

If (result = ERROR_INSUFFICIENT_BUFFER) Then

buffer = Marshal.AllocHGlobal(Convert.ToInt32(size))

result = GetIfTable(buffer, size, False)

Else

Throw New System.ComponentModel.Win32Exception(result)

End If

If (result <> NO_ERROR) Then

Throw New System.ComponentModel.Win32Exception(result)

Else

Dim count As Integer = Marshal.ReadInt32(buffer)

Dim ptr As Integer = buffer.ToInt32() + Marshal.SizeOf(GetType(Integer))

Dim ifRow As MIB_IFROW

Dim description As String

Dim bytesin, bytesout As String

Dim dummy As Integer

For i As Integer = 1 To count

ifRow = CType(Marshal.PtrToStructure(New IntPtr(ptr), GetType(MIB_IFROW)),
MIB_IFROW)

description = System.Text.Encoding.ASCII.GetString(ifRow.bDescr)

ptr += Marshal.SizeOf(GetType(MIB_IFROW))

description = Trim(Replace(Replace(Trim(description), Chr(10), ""), Chr(13),
""))

Console.WriteLine(description)

dummy = 1

bytesin = ""

Do While dummy <= ifRow.dwInOctets.ToString.Length

If dummy = 4 Or dummy = 7 Or dummy = 10 Or dummy = 13 Or dummy = 16 Or dummy
= 19 Or dummy = 22 Then

bytesin = "." & bytesin

End If

If ifRow.dwInOctets.ToString.Length > 2 Then

bytesin =
ifRow.dwInOctets.ToString.Substring(ifRow.dwInOctets.ToString.Length -
dummy, 1) & bytesin

Else

bytesin = ifRow.dwInOctets.ToString

End If

dummy += 1

Loop



dummy = 1

bytesout = ""

Do While dummy <= ifRow.dwOutOctets.ToString.Length

If dummy = 4 Or dummy = 7 Or dummy = 10 Or dummy = 13 Or dummy = 16 Or dummy
= 19 Or dummy = 22 Then

bytesout = "." & bytesout

End If

If ifRow.dwOutOctets.ToString.Length > 2 Then

bytesout =
ifRow.dwOutOctets.ToString.Substring(ifRow.dwOutOctets.ToString.Length -
dummy, 1) & bytesout

Else

bytesout = ifRow.dwOutOctets.ToString

End If

dummy += 1

Loop

Console.WriteLine("inp: " & ifRow.dwInUcastPkts.ToString & " outp: " &
ifRow.dwOutUcastPkts.ToString)

Console.WriteLine("in: " & bytesin & " out: " & bytesout)

Next

End If

Catch ex As Exception

Throw ex

Finally

If buffer.ToInt32() <> 0 Then

Marshal.FreeHGlobal(buffer)

End If

End Try

End Sub

..............;;

see other post.
 
N

newbie

I think I've found the problem.

The UInt32 value type represents unsigned integers with values ranging from
0 to 4,294,967,295.

thats why i never get a value that is more then 4GB !

Is there a counter that counts the overflows ?

bytesout = overflowcounter * 4,294,967,295 + currentUINT32counter.

that would be the correct value...
 
N

newbie

hm I don't think it overflows..
because inoctets / outoctets are DWORDS.

But in VB.NET you say that they are uint32.
But if I change that inoctets in ifrow to uint64
I really get a wrong value.
 
G

Guest

DWORD in WINAPI is exactly the same what uint32 is in .NET. Do not change
anything in this structure :D. Could you check if the Task Manager value
restarts too (run Task Magaer, go to Newtorking Tab, select
Menu->View->Select Columns)? If it does, it means Lan Connection Status
counts value overflows internally. If you disable and enable connection value
restarts to 0.
 
N

newbie

yes it also resets.
So i have to manually keep the overflow coints. and manually count in
strings. so i never get an overflow.
Thank you for helping me !.
btw, SNMP trap.. also resets on 4GB.

Is there a way to get the internal overflow count of the status lan ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top