Retreive bytes received

Hi,
Just wondering How do you retreive the bytes received from an internet connection using VB6.

Thanks
Dave Steers
dsteersAsked:
Who is Participating?
 
BozzoCageCommented:
dsteers, I'm very sorry, but I'm unable to devote my time to this question anymore. You know, "experts" should help with tips for things they really master. I don't master the area with which I was trying to help you, but I wanted to learn about it through help. That means it takes me a LOT of time, which I don't have anymore.

So... if this question is enough important to you, then delete this one and open new thread with same topic. Please don't just give me a grade of C - rather delete this question and you'll get your points back.

Regards,
  BozzoCage
0
 
JonFish85Commented:
hmm and 50 points is for an easy question?
0
 
dsteersAuthor Commented:
POINTS HUH !!!!!!!
Is that all you want.

Ok then.
50 it is (for a Easy question).
:)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
dsteersAuthor Commented:
POINTS HUH !!!!!!!
Is that all you want.

Ok then.
50 it is (for a Easy question).
:)
0
 
dsteersAuthor Commented:
!!!!!WOW!!!!! Double post,don't get excited it's just the one 50.
:)
0
 
dsteersAuthor Commented:
Ok enough stuffing around,I have increased the points to an acceptable level.
Some help would be much appreciated.

Thanks
Dave Steers
0
 
JonFish85Commented:
ok, well, I really doubt that it is possible... To get more response here, you might try posting a 0 point question again in VB area, "200 Points - Bytes Recieved" or something with a link to this question. Probably the answer you will get is to use a proxy server somehow...

Sorry I couldnt help more!
0
 
3rsrichardCommented:
It depends on the type of internet connection you are talking about.
You can create a simple UDP connection, for instance, using the
built in facilities of VB and your Windows computer, there are examples
in the MSDN library that comes with VB.

If you want to establish an HTTP, ftp, SMT  or other connection from within VB then
you'll probably need a 3rd party library of functions to help you.

Just what do you want to do?
0
 
dsteersAuthor Commented:
I'm looking how to retreive the total bytes sent and received just like the windows application does (the one on the bottom left next to the clock).
Via a Dial-up connection.

Thanks
Dave Steers
0
 
BozzoCageCommented:
Use this:
Bandwidth meter
http://www.planet-source-code.com/xq/ASP/txtCodeId.23893/lngWId.1/qx/vb/scripts/ShowCode.htm

With this sample you can view ALL transfer details from ALL interfaces, but of course you can use only the one you need (from internet connection (PPP)).

If you need more details/explanation, just ask.

Regards,
  BozzoCage
0
 
dsteersAuthor Commented:
I'll have a look at it and get back to you.
0
 
dsteersAuthor Commented:
On the right track.It's what I want just it doesn't line up with the windows DUN.
0
 
BozzoCageCommented:
Well, then I'll dig deeper into MSDN and get you a solution :)
0
 
dsteersAuthor Commented:
Thanks,I'd Appreciate that a lot.
0
 
BozzoCageCommented:
I found a solution that would work on Win2K only (and newer). If that's not a problem, just tell me and I'll make a sample app and post it.
In meantime ... I'm looking for "win version independent" way.
0
 
BozzoCageCommented:
Now I got one that would work on NT4 too.
Tell me ... what version of Win must function support?
(first sample I provided requires at least Win98).
0
 
dsteersAuthor Commented:
WEll if possible I would like it to work on 95/98/ME/2000 and NT.
Thanks,Hope this isn't too much to ask.
You will tell me if it is,wont you :)

Regards
Dave Steers
0
 
BozzoCageCommented:
This is all I am able to construct.
One drawback: used API works only on Win 98/2000 and NT4 with SP4 (and most probably ME)
Another one: if you have more than one modem, ... I don't know how will program handle that (how will API return that).
I guess each will be different device, all of type PPP. I was unable to somehow "link" physically present devices (modems,...) with interface names ("WAN (PPP/SLIP) Interface").

You can test it by copying all code behind a form and then add a command button to it. Click it, and in Debug window you'll see output as:

Interface no. 1: WAN (PPP/SLIP) Interface
Bytes sent: 46934
Bytes received: 250851
--------------------------------------------

In final program you will probably use Timer control to run this function every second or so.



Option Explicit

'-------------------------------------------

Private Type MIB_IFROW
    wszName(0 To 511) As Byte
    dwIndex As Long             '// index of the interface
    dwType As Long              '// type of interface
    dwMtu As Long               '// max transmission unit
    dwSpeed As Long             '// speed of the interface
    dwPhysAddrLen As Long       '// length of physical address
    bPhysAddr(0 To 7) As Byte   '// physical address of adapter
    dwAdminStatus As Long       '// administrative status
    dwOperStatus As Long        '// operational status
    dwLastChange As Long        '// last time operational status changed
    dwInOctets As Long          '// octets received
    dwInUcastPkts As Long       '// unicast packets received
    dwInNUcastPkts As Long      '// non-unicast packets received
    dwInDiscards As Long        '// received packets discarded
    dwInErrors As Long          '// erroneous packets received
    dwInUnknownProtos As Long   '// unknown protocol packets received
    dwOutOctets As Long         '// octets sent
    dwOutUcastPkts As Long      '// unicast packets sent
    dwOutNUcastPkts As Long     '// non-unicast packets sent
    dwOutDiscards As Long       '// outgoing packets discarded
    dwOutErrors As Long         '// erroneous packets sent
    dwOutQLen As Long           '// output queue length
    dwDescrLen As Long          '// length of bDescr member
    bDescr(0 To 255) As Byte    '// interface description
End Type

Public Enum InterfaceTypes
    MIB_IF_TYPE_OTHER = 1
    MIB_IF_TYPE_ETHERNET = 6
    MIB_IF_TYPE_TOKENRING = 9
    MIB_IF_TYPE_FDDI = 15
    MIB_IF_TYPE_PPP = 23
    MIB_IF_TYPE_LOOPBACK = 24
    MIB_IF_TYPE_SLIP = 28
End Enum



Private Const ERROR_NOT_SUPPORTED = 50&
Private Const ERROR_SUCCESS = 0&


Private Declare Function GetIfTable Lib "iphlpapi" (ByRef pIfRowTable As Any, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)


Private Type type_IF_info   ' interface info
    sName As String
    lSent As Long
    lReceived As Long
End Type

'-------------------------------------------

Sub Test()
    Dim i As Integer
    Dim if_info() As type_IF_info
    Dim retVal As Boolean
   
    'you can change type of interfaces to "listen" to by changing
    'first parameter of function (for ETHERNET it would be MIB_IF_TYPE_ETHERNET)
    retVal = GetInterfaceInfo(MIB_IF_TYPE_PPP, if_info)
    If retVal = True Then
        For i = 0 To UBound(if_info)
            Debug.Print "Interface no. " & i + 1 & ": " & if_info(i).sName
            Debug.Print "Bytes sent: " & if_info(i).lSent
            Debug.Print "Bytes received: " & if_info(i).lReceived
            Debug.Print "--------------------------------------------"
        Next i
    Else
        Debug.Print "No Interface of specified type found!"
    End If
End Sub

Private Function GetInterfaceInfo(ByVal in_IFType As InterfaceTypes, ByRef out_IFInfo() As type_IF_info) As Boolean
    Dim arrBuffer()     As Byte
    Dim arrCount        As Integer
    Dim lngSize         As Long
    Dim lngRetVal       As Long
    Dim lngRows         As Long
    Dim i               As Integer
    Dim j               As Integer
    Dim IfRowTable      As MIB_IFROW
    Dim if_info()       As type_IF_info

    'Call the GetIfTable just to get the buffer size into the lngSize variable
    lngRetVal = GetIfTable(ByVal 0&, lngSize, 0)

    If lngRetVal = ERROR_NOT_SUPPORTED Then
        'This API works only on Win 98/2000 and NT4 with SP4
        MsgBox "IP Helper is not supported by this system."
        Exit Function
    End If

    'Prepare the buffer
    ReDim arrBuffer(0 To lngSize - 1) As Byte

    'And call the function one more time
    lngRetVal = GetIfTable(arrBuffer(0), lngSize, 0)

    If lngRetVal = ERROR_SUCCESS Then
        'The first 4 bytes (the Long value) contain the quantity of the table rows
        'Get that value into the lngRows variable
        CopyMemory lngRows, arrBuffer(0), 4

        For i = 1 To lngRows
            'Copy the table row data to the IfRowTable structure
            CopyMemory IfRowTable, arrBuffer(4 + (i - 1) * Len(IfRowTable)), Len(IfRowTable)

            If IfRowTable.dwType = in_IFType Then
                ' just array management
                If arrCount > 0 Then
                    ReDim Preserve out_IFInfo(UBound(out_IFInfo))
                Else
                    ReDim out_IFInfo(0)
                End If
                   
                out_IFInfo(arrCount).sName = Left(StrConv(IfRowTable.bDescr, vbUnicode), IfRowTable.dwDescrLen)
                out_IFInfo(arrCount).lReceived = IfRowTable.dwInOctets
                out_IFInfo(arrCount).lSent = IfRowTable.dwOutOctets
               
                arrCount = arrCount + 1
            End If
        Next i

    End If
   
    If arrCount > 0 Then
        GetInterfaceInfo = True
    Else
        GetInterfaceInfo = False
    End If

End Function



Private Sub Command1_Click()
    Call Test
End Sub


-------
Would I get points at http://www.experts-exchange.com/jsp/qShow.jsp?qid=20144450 too?

Regards,
  BozzoCage
0
 
dsteersAuthor Commented:
Give us a while to test it out fully and I'll get back to you.

Thaks
Dave Steers
0
 
dsteersAuthor Commented:
Sorry unfortunately this wasn't what I was looking for.
I have found out where windows gets it's values from.
It's under HKEY_DNY_DATA.
I need to either be able to change values in this folder,which I cannot do by regedit it just says "Cannot create key.Error Writing to the Registry".
If there is any way around this it would be great,otherwise could you please tell me how to read values of Binary's in this folder.As the methods I have tried fail when I try to read a binary file.
I realise this is a bit off the topic of the question,but I see this as the only alternative.

Thanks again,
Dave Steers
0
 
BozzoCageCommented:
Unfortunatelly:
Note that HKEY_DYN_DATA is a valid tree for Windows 95 and Windows 98 computers only.

GetBinaryValue Method in Class StdRegProv:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/hh/wmisdk/r_prov_8bee.asp

Q174631 - HOWTO: Access the Performance Registry Under Windows 95
http://support.microsoft.com/support/kb/articles/Q174/6/31.ASP

Q145679 - HOWTO: Use the Registry API to Save and Retrieve Setting
http://support.microsoft.com/support/kb/articles/Q145/6/79.asp

-------------
From "Ask Dr. GUI #43", November/December 1998:


How Am I Performing?
Dear Dr. GUI,
Good Doctor,

Windows NT now has pdh.dll for easy reading of performance data. Is there such a thing for Windows 95/98?

Thanks,

Eric Renish

Dr. GUI replies:
Dr. GUI agrees with you. Wouldn't it be nice if there were? Unfortunately, there is no equivalent pdh.dll (Performance Data Helper Library) for Windows 95/98 as there is for Windows NT. The PDH Library was designed to make it easier for software developers to retrieve performance data on Windows NT. An application can retrieve performance data on Windows NT using RegQueryValueEx with the HKEY_PERFORMANCE_DATA built-in registry key. However, formatting the retrieved data to be readable information is very complex-thus the need for a helper library.

Windows 95/98 does provide a way to collect its performance data using RegQueryValueEx using HKEY_DYN_DATA. Retrieving the data and formatting it is relatively simple compared to the process for Windows NT. More information about retrieving Windows 95/98 performance data can be found in the following Microsoft Knowledge Base article, Q174631: "HOWTO: Access the Performance Registry Under Windows 95," located at http://support.microsoft.com/support/kb/articles/q174/6/31.asp.

-------

I think I somewhere read that this registry hive is read-only (would make sense), but I was unable to find such statement again.

I knew those keys are not on Win2000, so I ignored this possibility. But - you could use one way to get perf data on W9x systems and another for NT systems. If you "like" this idea and need more samples, just say so.

(for NT/2000)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/hh/pdh/perfdata_0pgn.asp


0
 
BozzoCageCommented:
I forgot to ask... WHY posted code isn't what you are looking for? What is missing/wrong/... so I can look for other solutions?
0
 
dsteersAuthor Commented:
The bytes don't match up with the ones with windows DUN ststus.
Also they don't match up with the registry,bytes etc under the HKEY_DYN_DATA.

Not sure why,but it shows a different number.
So I deduced that if the Win DUN is showing the same as the registry,those 2 must be correct.
I could be wrong.
Thanks for your Continued help.

Dave Steers
0
 
dsteersAuthor Commented:
Yeah,
If Possible I would love some samples for both 95 and NT.
And I will be more than happy to award you both ammount of points.
With the NT,I think using the PDH.dll is the definate way to go,saves a lot of stuffing around.So that sample would be helpful aswell.

Thanks
Dave Steers
0
 
dsteersAuthor Commented:
I've noticed all the PDH samples supplied by Microsoft are all in C/C++.
Haven't been able to find any in VB yet.
0
 
BozzoCageCommented:
No problem... I "speak" VB and C++ (among others), I'll write sample app, just give me some more time...

Regarding different values - function I provided returns "octets", not bytes... not exactly the same... But didn't done thorough testing, so I'm not sure.
0
 
dsteersAuthor Commented:
BozzoCage,
Just wondering if your still there :)
Just a little reminder,no hurry.I realise your busy.

Regards
Dave Steers
0
 
BozzoCageCommented:
I didn't forgot about you and I didn't meant so much time when I said I need some more time...
Let's say I have serious problems with my exams, so I had to stop my non-school activities. I surelly will provide you a solution, but you'll have to wait a little more (max to 22.9.2001)

Regards
  BozzoCage
0
 
dsteersAuthor Commented:
oh yeah that's fine.
Take your time,get those exams over first.
And Good luck in them too :)

Regards
Dave Steers
0
 
dsteersAuthor Commented:
Bozzo,
Just wondering if you have forgotten about this?

Regards
Dave
0
 
BozzoCageCommented:
No, still think of it from time to time (when I "meet" little pieces of papers I wrote when I was searching for appropriate functions to solve your problem.
Thanks for reminding me that this is still "actual".
I'll try to make it today... when I come home.

Btw.. I did most of the exams, but not enough, so I actually "failed"...
0
 
dsteersAuthor Commented:
Sorry to hear that,
Oh well - it's not the end of the world :)
0
 
MoondancerCommented:
Please update/finalize this question.

Thank you,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
MoondancerCommented:
dsteers---->  Please advise what you want done here.

Moondancer
Community Support Moderator @ Experts Exchange
0
 
dsteersAuthor Commented:
That's ok BozzoCage, I understand.
Thanks for your help, I've decided to give you the points anyway.
Have fun :)

Thanks Again
Dave
0
 
dsteersAuthor Commented:
BozzoCage,
I understand, thanks for your help.

Thanks Again
Dave
0
 
MoondancerCommented:
Thank you, Dave, for returning to your questions and putting the finishing touches on them.

Moondancer
Community Support Moderator @ Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.