gpt4 book ai didi

.net - 如何计算计算机下载的数量?

转载 作者:可可西里 更新时间:2023-11-01 11:22:39 27 4
gpt4 key购买 nike

我目前正在开发一个 .NET 网吧管理程序,并且想计算网吧中每台计算机从 Internet 下载的数据量,因为用户必须为他们的下载量付费。

我相信 Windows 中必须有某种 API 才能给我这个。我应该看哪里?

谢谢大家

最佳答案

我刚找到 System.Net.NetworkInformation 命名空间并编写了以下代码:

NetworkInterface[] networkInterfaces = 
NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in networkInterfaces)
{
IPv4InterfaceStatistics stats = ni.GetIPv4Statistics();
IPInterfaceProperties props = ni.GetIPProperties();
Console.WriteLine("{0} ({1:#,##0.00}Mb/s, {2})",
ni.Name, ni.Speed / 1024D / 1024D, ni.OperationalStatus);
Console.WriteLine("\t{0}", ni.Description);

Console.WriteLine("\t{0:#,##0.00}Mb sent, {1:#,##0.00}Mb received",
stats.BytesSent / 1024D / 1024D, stats.BytesReceived / 1024D / 1024D);
Console.WriteLine();
}

我得到了这个输出:

Local Area Connection 2 (953,67Mb/s, Up)        Realtek RTL8169/8110 Family PCI Gigabit Ethernet NIC (NDIS 6.0)        1.906,92Mb sent, 483,77Mb receivedLocal Area Connection 3 (9,54Mb/s, Down)        D-Link DFE-520TX PCI Fast Ethernet Adapter        0,00Mb sent, 0,00Mb receivedLoopback Pseudo-Interface 1 (1.024,00Mb/s, Up)        Software Loopback Interface 1        0,00Mb sent, 0,00Mb received

HTH

关于.net - 如何计算计算机下载的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1593674/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com