Solved

Retreive bytes received

Posted on 2001-06-24
37
435 Views
Last Modified: 2011-08-18
Hi,
Just wondering How do you retreive the bytes received from an internet connection using VB6.

Thanks
Dave Steers
0
Comment
Question by:dsteers
  • 20
  • 11
  • 3
  • +2
37 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6223411
hmm and 50 points is for an easy question?
0
 

Author Comment

by:dsteers
ID: 6224339
POINTS HUH !!!!!!!
Is that all you want.

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

Author Comment

by:dsteers
ID: 6224342
POINTS HUH !!!!!!!
Is that all you want.

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

Author Comment

by:dsteers
ID: 6224368
!!!!!WOW!!!!! Double post,don't get excited it's just the one 50.
:)
0
 

Author Comment

by:dsteers
ID: 6240824
Ok enough stuffing around,I have increased the points to an acceptable level.
Some help would be much appreciated.

Thanks
Dave Steers
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6241020
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
 
LVL 3

Expert Comment

by:3rsrichard
ID: 6244702
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
 

Author Comment

by:dsteers
ID: 6308399
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6361019
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
 

Author Comment

by:dsteers
ID: 6363548
I'll have a look at it and get back to you.
0
 

Author Comment

by:dsteers
ID: 6367718
On the right track.It's what I want just it doesn't line up with the windows DUN.
0
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6367834
Well, then I'll dig deeper into MSDN and get you a solution :)
0
 

Author Comment

by:dsteers
ID: 6368055
Thanks,I'd Appreciate that a lot.
0
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6368248
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6368819
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
 

Author Comment

by:dsteers
ID: 6371974
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6374481
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
 

Author Comment

by:dsteers
ID: 6375368
Give us a while to test it out fully and I'll get back to you.

Thaks
Dave Steers
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:dsteers
ID: 6387734
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6387844
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6387850
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
 

Author Comment

by:dsteers
ID: 6392315
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
 

Author Comment

by:dsteers
ID: 6392363
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
 

Author Comment

by:dsteers
ID: 6392370
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
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6392428
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
 

Author Comment

by:dsteers
ID: 6466597
BozzoCage,
Just wondering if your still there :)
Just a little reminder,no hurry.I realise your busy.

Regards
Dave Steers
0
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6466804
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
 

Author Comment

by:dsteers
ID: 6466871
oh yeah that's fine.
Take your time,get those exams over first.
And Good luck in them too :)

Regards
Dave Steers
0
 

Author Comment

by:dsteers
ID: 6540603
Bozzo,
Just wondering if you have forgotten about this?

Regards
Dave
0
 
LVL 2

Expert Comment

by:BozzoCage
ID: 6559973
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
 

Author Comment

by:dsteers
ID: 6570502
Sorry to hear that,
Oh well - it's not the end of the world :)
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6724444
Please update/finalize this question.

Thank you,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 2

Accepted Solution

by:
BozzoCage earned 250 total points
ID: 6724819
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6725140
dsteers---->  Please advise what you want done here.

Moondancer
Community Support Moderator @ Experts Exchange
0
 

Author Comment

by:dsteers
ID: 6726050
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
 

Author Comment

by:dsteers
ID: 6726065
BozzoCage,
I understand, thanks for your help.

Thanks Again
Dave
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6726630
Thank you, Dave, for returning to your questions and putting the finishing touches on them.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now