Thank you for visiting → Compete For ← If you find anything useful leave me a comment and share. Interested in Arduino, C#, Unity3D, Game Creation, VB.NET, learning and most important of all Sharing!.
Close Notification
Open Notification

VB.NET 2010 View Network Adapter Monitor Downloads and Uploads Data

VB.NET 2010 View Network Adapter Monitor Downloads and Uploads Data

DOWNLOAD – VB.NET 2010 Express Network Project File

DOWNLOAD – Sniz on the Network Monitor Standalone Application

I take NO RESPONSIBILITY for what damage this may cause.

I needed an application that could help identify what was using all the bandwidth of our internet connection, so I decided to write the application myself. The code came from all over the place as using WMI is insane confusing.

Well this was a massive pain to get working as I have never used WMI but having found and awesome application from Microsoft called “WMI Code Creator v1.0″ made it possible.

When the application is run it minimise’s to the task menu. To use just Select the network adapter you want to monitor and click “Start Now”. All the network adapters installed should show up in the listbox. The total downloads and upload amounts are the Adapters Total data transfer since the last boot.

ok Now for some code…..

Declare some stuff and generate list of Network Adapters and add to listbox called lstAdapters

    Dim strComputer, objWMIService, total_sent, total_received, total_obj

        'create list of adapters
            Dim searcher As New ManagementObjectSearcher( _
                "root\CIMV2", _
                "SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = True")

            For Each queryObj As ManagementObject In searcher.Get()
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try

Now the Meat of the code

 Sub Object_OnScriptEnter()

        total_sent = ""
        total_received = ""

        ' get total bytes received and sent
            strComputer = "."
            objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")

            ' get total received
            total_obj = objWMIService.ExecQuery("SELECT * FROM MSNdis_ReceivesOk")

            For Each objItem In total_obj
                'If objItem.InstanceName = "Realtek PCIe GBE Family Controller" Then

                If objItem.InstanceName = lstAdapters.SelectedItem.ToString Then
                    total_received = objItem.NdisReceivesOk * 1.35 / 1000 '& " received " & vbNewLine
                  End If

            ' get total sent
            total_obj = objWMIService.ExecQuery("SELECT * FROM MSNdis_TransmitsOk")

            For Each objItem In total_obj
                If objItem.InstanceName = lstAdapters.SelectedItem.ToString Then
                    total_sent = objItem.NdisTransmitsOk * 1.35 / 1000
                End If

Now to Call OnScriptEnter() using a timer

    Private Sub tmrNetworkStat_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrNetworkStat.Tick

        End Try
    End Sub

Leave a reply