|
-
Sep 2nd, 2012, 03:06 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 2nd, 2012, 03:49 PM
#2
Re: tracking internet usage
-
Sep 2nd, 2012, 03:55 PM
#3
Thread Starter
Hyperactive Member
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
-
Sep 2nd, 2012, 03:59 PM
#4
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:
Private startDownloaded As Long
Private startUploaded As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim interfaceStatistics As IPv4InterfaceStatistics = NetworkInterface.GetAllNetworkInterfaces()(0).GetIPv4Statistics()
startDownloaded = interfaceStatistics.BytesReceived
startUploaded = interfaceStatistics.BytesSent
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim interfaceStatistics As IPv4InterfaceStatistics = NetworkInterface.GetAllNetworkInterfaces()(0).GetIPv4Statistics()
Debug.Print(String.Format("Downloaded: {0} bytes", (interfaceStatistics.BytesReceived - startDownloaded)))
Debug.Print(String.Format("Uploaded: {0} bytes", (interfaceStatistics.BytesSent - startUploaded)))
End Sub
-
Sep 2nd, 2012, 04:07 PM
#5
Thread Starter
Hyperactive Member
Re: tracking internet usage
Ok thanks. It does give me this one error
'IPv4InterfaceStatistics' is not defined.
-
Sep 2nd, 2012, 04:12 PM
#6
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.
-
Sep 2nd, 2012, 04:15 PM
#7
Re: tracking internet usage
 Originally Posted by sherlockturtle
Ok thanks. It does give me this one error
'IPv4InterfaceStatistics' is not defined.
Try using the correction options. Add ....
Imports System.Net.NetworkInformation
-
Sep 2nd, 2012, 04:32 PM
#8
Thread Starter
Hyperactive Member
Re: tracking internet usage
So. I tried loading some pages and diferent things and nothing seams to happen with recieved and sent?
-
Sep 2nd, 2012, 04:40 PM
#9
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.
-
Sep 2nd, 2012, 04:47 PM
#10
Thread Starter
Hyperactive Member
Re: tracking internet usage
Thats what I did. I used a timer. Every 20 seconds
Code:
TextBox1.Text = interfaceStatistics.BytesReceived
TextBox2.Text = interfaceStatistics.BytesSent
-
Sep 2nd, 2012, 08:27 PM
#11
Re: tracking internet usage
 Originally Posted by sherlockturtle
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.
-
Sep 3rd, 2012, 09:13 AM
#12
Thread Starter
Hyperactive Member
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.
-
Sep 3rd, 2012, 12:26 PM
#13
Addicted Member
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
-
Sep 3rd, 2012, 01:16 PM
#14
Thread Starter
Hyperactive Member
Re: tracking internet usage
Hmm... I could but is there a way to do it from one?
-
Sep 3rd, 2012, 01:29 PM
#15
Re: tracking internet usage
 Originally Posted by sherlockturtle
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.
-
Sep 3rd, 2012, 01:33 PM
#16
Thread Starter
Hyperactive Member
Re: tracking internet usage
ok. Would you have any idea on how to do what I want? What you did still helped.
-
Oct 24th, 2013, 11:39 AM
#17
New Member
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
-
Oct 24th, 2013, 05:03 PM
#18
Re: tracking internet usage
Divide the value by 1024 to get KiloBytes, another division by 1024 gives MegaBytes.
-
Oct 25th, 2013, 02:02 AM
#19
New Member
Re: tracking internet usage
 Originally Posted by Arnoutdv
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.
-
Oct 25th, 2013, 07:04 AM
#20
Re: tracking internet usage
See this thread that talks about converting.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|