Results 1 to 20 of 20

Thread: tracking internet usage

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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 2012
    Posts
    8,245

    Re: tracking internet usage

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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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 2005
    Posts
    1,834

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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 2005
    Posts
    1,834

    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 2012
    Posts
    8,245

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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 2005
    Posts
    1,834

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    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 2008
    Location
    Reading, UK
    Posts
    192

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Posts
    346

    Re: tracking internet usage

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

  15. #15
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Posts
    346

    Re: tracking internet usage

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

  17. #17
    New Member
    Join Date
    Oct 2013
    Posts
    2

    Re: tracking internet usage

    hello up for this thread.!

    thank you for this code you saved my day ..!!

    but in this code how can i convert all data into bytes > Mega Bytes > Gigabytes

    in this line.!

    Code:
    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

  18. #18
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,735

    Re: tracking internet usage

    Divide the value by 1024 to get KiloBytes, another division by 1024 gives MegaBytes.

  19. #19
    New Member
    Join Date
    Oct 2013
    Posts
    2

    Re: tracking internet usage

    Quote Originally Posted by Arnoutdv View Post
    Divide the value by 1024 to get KiloBytes, another division by 1024 gives MegaBytes.
    hello thank you for your response.!

    I'm just a beginner for this program and i don't know how to Divide them can you give me an example

    on how to implement here in this line.

    Code:
    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
    thanks.

  20. #20
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: tracking internet usage

    See this thread that talks about converting.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

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



Click Here to Expand Forum to Full Width