计算下载的字节数 [英] Count the amount of bytes downloaded

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

问题描述

你好

我想计算使用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.

推荐答案

我们需要更多信息来帮助您.

但是,如果您要查找的是基本信息. System.Net.NetworkInformation命名空间 [IPv4InterfaceStatistics [
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:
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");
    }
  }
}


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆