• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 746
  • Last Modified:

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.
1 Solution
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


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now