C#上网流量统计

昨天,听到领导对java的同事说,做一个流量统计功能,看你的程序是不是把带宽占完了,占完了好申请更多的带宽,现在什么360,金山,QQ管家各种软件都在做流量统计,就想自己能不能也实现一个呢/?

<wbr><wbr><wbr>网上搜索了一下,没找到C#做流量统计的资料,我想C++应该可以三,继续搜索,意外发现windows有自己的流量统计功能,只需要去取出来就好了。</wbr></wbr></wbr>

<wbr><wbr><wbr>O~LA~这么简单的事情C#应该有函数的,MSDN打开,网络通信相关的命名空间看看去,O~找到了,原来确实是很简单的,贴出来大家看看:</wbr></wbr></wbr>

using System.Net.NetworkInformation;IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); Console.WriteLine("Interface information for {0}.{1} ", computerProperties.HostName, computerProperties.DomainName); if (nics == null || nics.Length < 1) { Console.WriteLine(" No network interfaces found."); return; } Console.WriteLine(" Number of interfaces .................... : {0}", nics.Length); foreach (NetworkInterface adapter in nics) { IPv4InterfaceStatistics ipv4Statistics = adapter.GetIPv4Statistics(); Console.WriteLine("send :{0}MB", ipv4Statistics.BytesSent / 1024 / 1024); Console.WriteLine("recieve :{0}MB", ipv4Statistics.BytesReceived / 1024 / 1024); }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值