Results 1 to 16 of 16

Thread: tracking internet usage

  1. #1
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    tracking internet usage

    Is there a way to get how many bites downloaded/uploaded to the internet since I opend my program? I want to track that.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,502

    Re: tracking internet usage

    There is ... but it's not easy! http://pinvoke.net/default.aspx/iphlpapi.GetIfTable

  3. #3
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    Thats in C# right? Sorry.. but id prefer vb. Just too get the hard number like 25 bites Downloaded 26 bites Uploaded

  4. #4
    Frenzied Member
    Join Date
    Nov 05
    Posts
    1,808

    Re: tracking internet usage

    Then convert it to vb.net. Go to Google, type "c# to vbnet" and you'll find a bunch of online converters.

    You can also try this.

    vb.net Code:
    1. Private startDownloaded As Long
    2.     Private startUploaded As Long
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim interfaceStatistics As IPv4InterfaceStatistics = NetworkInterface.GetAllNetworkInterfaces()(0).GetIPv4Statistics()
    6.         startDownloaded = interfaceStatistics.BytesReceived
    7.         startUploaded = interfaceStatistics.BytesSent
    8.     End Sub
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         Dim interfaceStatistics As IPv4InterfaceStatistics = NetworkInterface.GetAllNetworkInterfaces()(0).GetIPv4Statistics()
    12.  
    13.         Debug.Print(String.Format("Downloaded: {0} bytes", (interfaceStatistics.BytesReceived - startDownloaded)))
    14.         Debug.Print(String.Format("Uploaded: {0} bytes", (interfaceStatistics.BytesSent - startUploaded)))
    15.     End Sub

  5. #5
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    Ok thanks. It does give me this one error
    'IPv4InterfaceStatistics' is not defined.

  6. #6
    Frenzied Member
    Join Date
    Nov 05
    Posts
    1,808

    Re: tracking internet usage

    Hover your mouse cursor over the red underscore, click on the red exclamation mark that appears and click on the 'Import' line.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,502

    Re: tracking internet usage

    Quote Originally Posted by sherlockturtle View Post
    Ok thanks. It does give me this one error
    'IPv4InterfaceStatistics' is not defined.
    Try using the correction options. Add ....

    Imports System.Net.NetworkInformation

  8. #8
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    So. I tried loading some pages and diferent things and nothing seams to happen with recieved and sent?

  9. #9
    Frenzied Member
    Join Date
    Nov 05
    Posts
    1,808

    Re: tracking internet usage

    Well, look at your immediate window or add two labels/textboxes to your form and use them instead of Debug.Print to show the information.

  10. #10
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    Thats what I did. I used a timer. Every 20 seconds
    Code:
            TextBox1.Text = interfaceStatistics.BytesReceived
            TextBox2.Text = interfaceStatistics.BytesSent

  11. #11
    PowerPoster Edgemeal's Avatar
    Join Date
    Sep 06
    Location
    WindowFromPoint(x,y)
    Posts
    3,133

    Re: tracking internet usage

    Quote Originally Posted by sherlockturtle View Post
    Thats what I did. I used a timer. Every 20 seconds
    (0).GetIPv4Statistics means use first interface which may not be the one used for your internet.
    Try populating a non-sorted combo box with the network interface names, then set the interface using the selected index, something like,

    Code:
    Imports System.Net.NetworkInformation
    
    Public Class Form1
        Private ipv4Stats As IPv4InterfaceStatistics
        Private nic As NetworkInterface
        Private startUploaded, startDownloaded As Long
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ' don't sort combo items, index used to make selection!
            ComboBox1.Sorted = False
            ' pop list with network adapter names
            Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
            For Each adapter As NetworkInterface In nics
                ComboBox1.Items.Add(adapter.Name)
            Next
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            ' select adapter to monitor...
            If ComboBox1.SelectedIndex > -1 Then
                nic = NetworkInterface.GetAllNetworkInterfaces(ComboBox1.SelectedIndex)
                ipv4Stats = nic.GetIPv4Statistics
                ' save current Bytes
                startDownloaded = ipv4Stats.BytesReceived
                startUploaded = ipv4Stats.BytesSent
                ' update labels/stats
                UpdateStats()
                ' start timer/auto update stats
                Timer1.Interval = 1000
                Timer1.Start()
            End If
        End Sub
    
        Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
            UpdateStats()
        End Sub
    
        Private Sub UpdateStats()
            Try
                ipv4Stats = nic.GetIPv4Statistics
                Label1.Text = String.Format("Downloaded: {0} bytes", ipv4Stats.BytesReceived - startDownloaded)
                Label2.Text = String.Format("Uploaded: {0} bytes", ipv4Stats.BytesSent - startUploaded)
            Catch ex As Exception
                Debug.WriteLine(ex.Message)
            End Try
        End Sub
    
    End Class
    Last edited by Edgemeal; Sep 2nd, 2012 at 09:22 PM.

  12. #12
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    Does this monitor my computer specifics internet? Or all teh computers on the network. Would it be possible to get each computer on the networks Upload and Download?

    -Thanks
    Last edited by sherlockturtle; Sep 3rd, 2012 at 11:15 AM.

  13. #13
    Addicted Member
    Join Date
    Sep 08
    Location
    Reading, UK
    Posts
    159

    Re: tracking internet usage

    Hi Sherlockturtle

    You put a small program like a service on each computer which logs their usage on a server then your program get the logs and adds it all up.

    Thats what id do

    Ian

  14. #14
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    Hmm... I could but is there a way to do it from one?

  15. #15
    PowerPoster Edgemeal's Avatar
    Join Date
    Sep 06
    Location
    WindowFromPoint(x,y)
    Posts
    3,133

    Re: tracking internet usage

    Quote Originally Posted by sherlockturtle View Post
    Does this monitor my computer specifics internet? Or all teh computers on the network.
    It monitors all traffic on the selected adpater, so for example if the adapter is on a LAN and you transfer files to/from other PCs it would see that traffic as well, so probably not what you wanted sorry,.. it works for me because I have two adapters, one for internet only and one for the LAN.

  16. #16
    Hyperactive Member
    Join Date
    Dec 11
    Posts
    346

    Re: tracking internet usage

    ok. Would you have any idea on how to do what I want? What you did still helped.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •