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

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.