How to obtain the bytes received and sent from an network interface card

Posted on 2008-11-06
Last Modified: 2012-08-14
Hi Experts, I want to able to capture the amount of data that is being transmitted and received based on a selected NIC card. Below are the 2 requirements that I need to fulfil:

a. To list all the network adapters found in the computer
b. Based on the selected network adapter, I need to record the amount of data that is being transmitted and received.

Please advice how to implement this solution in VB.NET 2005. Please provide a sample code snippet.
Question by:bpyeo
    1 Comment
    LVL 59

    Accepted Solution

    Hello bpyeo,

    Something like this as an exampled (see code snippet).


    Module Module1 
        Sub Main()
            Dim netAdapters() As System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() 
            For Each netAdapter As System.Net.NetworkInformation.NetworkInterface In netAdapters
                If netAdapter.Name = "Local Area Connection 2" Then
                    Dim netStatistics As System.Net.NetworkInformation.IPv4InterfaceStatistics = netAdapter.GetIPv4Statistics()
                    Console.WriteLine(String.Format("{0} has {1} bytes received and {2} bytes sent so far.", netAdapter.Name, netStatistics.BytesReceived, netStatistics.BytesSent)) 
                End If
        End Sub 
    End Module

    Open in new window


    Featured Post

    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

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 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

    17 Experts available now in Live!

    Get 1:1 Help Now