Click here to Skip to main content
15,908,173 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hello

I want to count the amount of bytes downloaded from Internet using c#. Like whatever did by the cafes. I want to write a code to perform the functionality.

please help me.
Posted
Comments
Sergey Alexandrovich Kryukov 25-May-11 17:31pm    
It depends on how you want to download. Also, why? Doesn't your downloaded file size tell you that? Or, you need a sum during session, certain period of time, what. What's the requirements for the code? What else should it do?
--SA
Sandeep Mewara 26-May-11 1:03am    
Add on more details with effort if any made.
[no name] 31-May-11 14:04pm    
Actually I want to create a Software that will handle all the work that a cyber cafe software perform.
for that I want the sum of to data downloaded via Internet through a browsers.

1 solution

We need more info to help you.

But if it is basic information you seek. System.Net.NetworkInformation Namespace[^] is a good place to start and under IPv4InterfaceStatistics [^] you can find info like BytesSent and BytesReceived.

Example:
C#
if (NetworkInterface.GetIsNetworkAvailable())
{
  NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
  foreach (NetworkInterface iface in interfaces)
  {
    if (iface.OperationalStatus == OperationalStatus.Up && iface.NetworkInterfaceType != NetworkInterfaceType.Loopback)
    {
      IPv4InterfaceStatistics stats = iface.GetIPv4Statistics();
      long bytesReceived = stats.BytesReceived;
      long bytesSent = stats.BytesSent;
      Console.WriteLine("Network: " + iface.Description + " (" + iface.Name + "), has sent: " + bytesSent + " bytes and received: " + bytesReceived + " bytes");
    }
  }
}
 
Share this answer
 
v2
Comments
[no name] 30-May-11 4:59am    
Thanks for your reply.
can you please give me any code!
Kim Togo 30-May-11 5:10am    
See updated answer. If the answer solve your problem. Please vote and press "Accept Answer". This way, you help other CP members to find solutions :-)
[no name] 31-May-11 13:56pm    
I don't want ByteRecived and ByteSent.
In a particular amount of time how many amount of data is received from the internet.

please help
Kim Togo 1-Jun-11 2:56am    
The ByteRecived and ByteSent is the overall amount of bytes that has passed the network interface and is not specific to Internet. If one computer copies 100MB of data, then this will reflect on ByteRecived and ByteSent counts.

Perhaps a better way to handles this, is in the core switch.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900