|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Re: Status Lan connection - bytes send / recievedWill try to come back with an example, for now try this one, http://www.dotnetforums.net/showthread.php?p=414139#post414139 -- Show quoteMilosz Skalecki MCP, MCAD "newbie" wrote: > Ok. thank you. > netstat -e --> its value resets each 5GB. > Just like the raw value of the Win32_PerfRawData_Tcpip_NetworkInterface > Really it does ! :-( > try code below, send + 5GB across the network and see again. You will see > the value has been reset. ( like netstat -e ) > > Imports System.Management > > 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.ToInt32(queryObj("BytesReceivedPersec")) > totaalverzonden = totaalverzonden + > Convert.ToInt32(queryObj("BytesSentPersec")) > totaal += Convert.ToInt64(queryObj("BytesTotalPersec")) > Next > > Console.WriteLine("Totaalonvangen: " & 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 > > > Now. This morning I have found something else on the net with GetIfTable. > And now you say also to do it with GetIfTable. > I have searched for a VB.NET example ( not C-code ) > But I only can find a VB6.0 application and a .NET application in C > > As you can see in the JPG both codes works fine. but it isn't a VB.NET code > / console application. > Could you help me ? I would like to output these 2 values in console. > > > > > > > > > > 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 -- 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 -- Show quoteMilosz Skalecki MCP, MCAD "newbie" wrote: > 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 > > > thank you,
but how can I use this class ? dim test as new ipapi .... ? Show quote "Milosz Skalecki" <mily***@REMOVEITwp.pl> schreef in bericht news:71BFB96E-8566-47D9-A4FC-A7885FD37E3D@microsoft.com... > -- 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 > > -- > Milosz Skalecki > MCP, MCAD > > > "newbie" wrote: > >> 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 >> >> >> 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. -- Show quoteMilosz Skalecki MCP, MCAD "newbie" wrote: > thank you, > but how can I use this class ? > dim test as new ipapi > .... > ? > > > "Milosz Skalecki" <mily***@REMOVEITwp.pl> schreef in bericht > news:71BFB96E-8566-47D9-A4FC-A7885FD37E3D@microsoft.com... > > -- 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 > > > > -- > > Milosz Skalecki > > MCP, MCAD > > > > > > "newbie" wrote: > > > >> 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 > >> > >> > >> > > > 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. 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... 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. 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. -- Show quoteMilosz Skalecki MCP, MCAD "newbie" wrote: > 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. > > > 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 ? Show quote "Milosz Skalecki" <mily***@REMOVEITwp.pl> schreef in bericht news:0922AC97-2A4A-4035-B301-C84FB1EADBF7@microsoft.com... > 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. > > -- > Milosz Skalecki > MCP, MCAD > > > "newbie" wrote: > >> 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. >> >> >> Dont know :( Try registry or assembler :)
-- Show quoteMilosz Skalecki MCP, MCAD "newbie" wrote: > 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 ? > > > "Milosz Skalecki" <mily***@REMOVEITwp.pl> schreef in bericht > news:0922AC97-2A4A-4035-B301-C84FB1EADBF7@microsoft.com... > > 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. > > > > -- > > Milosz Skalecki > > MCP, MCAD > > > > > > "newbie" wrote: > > > >> 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. > >> > >> > >> > > > |
|||||||||||||||||||||||