本文介绍了计算下载的字节数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想计算使用c#从Internet下载的字节数.就像咖啡店所做的一样.............................................................................................................................................................................................我想编写一个代码来执行功能.

请帮助我.

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.

推荐答案

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");
    }
  }
}


这篇关于计算下载的字节数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:41