Is there a way to get how many bites downloaded/uploaded to the internet since I opend my program? I want to track that.
Is there a way to get how many bites downloaded/uploaded to the internet since I opend my program? I want to track that.
There is ... but it's not easy! http://pinvoke.net/default.aspx/iphlpapi.GetIfTable
Thats in C# right? Sorry.. but id prefer vb. Just too get the hard number like 25 bites Downloaded 26 bites Uploaded
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))) End Sub
Ok thanks. It does give me this one error
'IPv4InterfaceStatistics' is not defined.
Hover your mouse cursor over the red underscore, click on the red exclamation mark that appears and click on the 'Import' line.
So. I tried loading some pages and diferent things and nothing seams to happen with recieved and sent?
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.
Thats what I did. I used a timer. Every 20 seconds
Code:TextBox1.Text = interfaceStatistics.BytesReceived TextBox2.Text = interfaceStatistics.BytesSent
(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.
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.
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
Hmm... I could but is there a way to do it from one?
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.
ok. Would you have any idea on how to do what I want? What you did still helped.