windows获取流量
来源:互联网 发布:网络借贷存管业务指引 编辑:程序博客网 时间:2024/05/17 02:27
一个轻量级的网络流量监控程序,只能在局域网中使用。
主要用到GetIfTable(),和GetIfEntry() 两个API。界面用QT做,可以隐藏在系统托盘中。
截图
核心代码如下
- void NetFlow::getFlow() {
- // 记录上一次函数调用时的总流量和时间,在后面计算流量速度的时候用到
- preInFlow = inFlow;
- preOutFlow = outFlow;
- preTime = currTime;
- inFlow = 0.0f;
- outFlow = 0.0f;
- currTime = GetTickCount();
- int i;
- pIfTable = (MIB_IFTABLE *) MALLOC(sizeof (MIB_IFTABLE));
- if (pIfTable == NULL) {
- printf("Error allocating memory needed to call GetIfTable/n");
- return;
- }
- dwSize = sizeof (MIB_IFTABLE);
- if (GetIfTable(pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
- FREE(pIfTable);
- pIfTable = (MIB_IFTABLE *) MALLOC(dwSize);
- if (pIfTable == NULL) {
- printf("Error allocating memory/n");
- return;
- }
- }
- if ((dwRetVal = GetIfTable(pIfTable, &dwSize, 0)) == NO_ERROR) {
- if (pIfTable->dwNumEntries > 0) {
- pIfRow = (MIB_IFROW *) MALLOC(sizeof (MIB_IFROW));
- if (pIfRow == NULL) {
- printf("Error allocating memory/n");
- if (pIfTable != NULL) {
- FREE(pIfTable);
- pIfTable = NULL;
- }
- return;
- }
- printf("/tNum Entries: %ld/n/n", pIfTable->dwNumEntries);
- // 枚举所有接口
- for (i = 0; i < (int) pIfTable->dwNumEntries; i++) {
- pIfRow->dwIndex = pIfTable->table[i].dwIndex;
- if ((dwRetVal = GetIfEntry(pIfRow)) == NO_ERROR) {
- // 排除环回接口的流量
- if(pIfRow->dwType != MIB_IF_TYPE_LOOPBACK) {
- inFlow += pIfRow->dwInOctets;
- outFlow += pIfRow->dwOutOctets;
- }
- }
- else {
- printf("GetIfEntry failed for index %d with error: %ld/n",
- i, dwRetVal);
- }
- }
- } else {
- printf("/tGetIfTable failed with error: %ld/n", dwRetVal);
- }
- }
- FREE(pIfTable);
- FREE(pIfRow);
- // 计算流量,速度=总流量 / 所经过的时间
- float inSpeed = (inFlow - preInFlow) / ((float)(currTime - preTime) / 1000.0f);
- float outSpeed = (outFlow - preOutFlow) / ((float)(currTime - preTime) / 1000.0f);
- char buffer[100];
- sprintf(buffer, "Download: %.2fk/s Upload: %.2fk/s", inSpeed / 1000.0f, outSpeed / 1000.0f);
- bodyEdit->setText(buffer);
- trayIcon->setToolTip(QString(buffer));
- }
下载地址:http://download.csdn.net/source/3040966
0 0
- windows获取流量
- windows获取进程流量
- 今天看了一下 windows 如何获取流量的接口
- VC获取网卡流量
- iOS 获取流量
- 获取进程流量信息
- Android获取流量信息
- windows流量监控
- C++在windows下获取本地流量和网速的程序
- 如何从Facebook获取流量
- android 2.1 获取手机流量
- Sigar获取网卡流量信息
- iphone获取当前流量信息
- 手机流量信息的获取
- Openwrt 获取客户端实时流量
- Android 获取应用流量信息
- 51la流量获取链接
- 32_获取流量信息
- DNS服务器配置
- eclipse生成jar包
- Ubuntu server启动脚本以及欢迎页定制
- EBS Form开发中复写on-lock触发器
- 张朝阳谈收购56:PGC/UGC若商业化,利润率将高于电视剧
- windows获取流量
- android listview scroll滑屏显示sqlite分页,类似聊天记录,listview动态添加sqlite分页数据
- Python 使用类实现简单的计时器
- java通过JDBC链接SQLServer2012
- SSH学习3:maven Struts Hello World
- 编写高效的C程序与C代码优化
- Convert object to json and json to object in C#
- BZOJ 3190 JLOI 2013 赛车 暴力
- 笔记-std::function<> && std::bind()