开发者

How do I calculate amount downloaded by a computer?

I'm currently working on a .NET Cybercafe management program and would like to calculate the amount of data downloaded from the Internet by each computer in the Cyberca开发者_开发问答fe, since users have to pay for their download amount.

I believe there has to be some sort of API in Windows to give me this. Where should I look?

Thanks everyone.


I just found System.Net.NetworkInformation namespace and wrote following code:

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

I got this output:

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 received

Local Area Connection 3 (9,54Mb/s, Down)
        D-Link DFE-520TX PCI Fast Ethernet Adapter
        0,00Mb sent, 0,00Mb received

Loopback Pseudo-Interface 1 (1.024,00Mb/s, Up)
        Software Loopback Interface 1
        0,00Mb sent, 0,00Mb received

HTH


I'd use some built for purpose solution. Google 'cybercafe management software' - there are tons of results:

e.g.: www.handycafe.com/


You can also read the performance counters on the system. See PerformanceCounter class in .NET. For a list of available performance counters on your machine. Start->Run Perfmon -> Do "Add Counters" to see the ones available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜