[100分求助]如何使用VC编程获取网卡当前的状态 - IT者

导读:
至少需要获取:
1、当前速度
2、是全双工的,还是半双工的
3、是否是自适应的
网友回复:SetupDiEnumDeviceInterfaces


你查下,我觉得应该可以
网友回复:用GetIfTable函数
网友回复:SetupDiEnumDeviceInterfaces


网友回复:up
网友回复:引用 1 楼 greatws 的回复:
SetupDiEnumDeviceInterfaces


你查下,我觉得应该可以
 


这是驱动级别使用的API吧.
网友回复:引用楼主 aopha 的帖子:
至少需要获取:
1、当前速度
2、是全双工的,还是半双工的
3、是否是自适应的
 


MSDN的代码
include
#include


#include


#include
#include


#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
/* Note: could also use malloc() and free() */


int main()
{


// Declare and initialize variables.


DWORD dwSize = 0;
DWORD dwRetVal = 0;


int i, j;


/* variables used for GetIfTable and GetIfEntry */
MIB_IFTABLE *pIfTable;
MIB_IFROW *pIfRow;


// Allocate memory for our pointers.
pIfTable = (MIB_IFTABLE *) MALLOC(sizeof (MIB_IFTABLE));
if (pIfTable == NULL) {
printf("Error allocating memory needed to call GetIfTable/n");
return 1;
}
// Make an initial call to GetIfTable to get the
// necessary size into dwSize
dwSize = sizeof (MIB_IFTABLE);
if (GetIfTable(pIfTable, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) {
FREE(pIfTable);
pIfTable = (MIB_IFTABLE *) MALLOC(dwSize);
if (pIfTable == NULL) {
printf("Error allocating memory needed to call GetIfTable/n");
return 1;
}
}
// Make a second call to GetIfTable to get the actual
// data we want.
if ((dwRetVal = GetIfTable(pIfTable, &dwSize, FALSE)) == NO_ERROR) {
printf("/tNum Entries: %ld/n/n", pIfTable->dwNumEntries);
for (i = 0; i < (int) pIfTable->dwNumEntries; i ) {
pIfRow = (MIB_IFROW *) & pIfTable->table[i];
printf("/tIndex[%d]:/t %ld/n", i, pIfRow->dwIndex);
printf("/tInterfaceName[%d]:/t %ws", i, pIfRow->wszName);
printf("/n");
printf("/tDescription[%d]:/t ", i);
for (j = 0; j < (int) pIfRow->dwDescrLen; j )
printf("%c", pIfRow->bDescr[j]);
printf("/n");
printf("/tType[%d]:/t ", i);
switch (pIfRow->dwType) {
case IF_TYPE_OTHER:
printf("Other/n");
break;
case IF_TYPE_ETHERNET_CSMACD:
printf("Ethernet/n");
break;
case IF_TYPE_ISO88025_TOKENRING:
printf("Token Ring/n");
break;
case IF_TYPE_PPP:
printf("PPP/n");
break;
case IF_TYPE_SOFTWARE_LOOPBACK:
printf("Software Lookback/n");
break;
case IF_TYPE_ATM:
printf("ATM/n");
break;
case IF_TYPE_IEEE80211:
printf("IEEE 802.11 Wireless/n");
break;
case IF_TYPE_TUNNEL:
printf("Tunnel type encapsulation/n");
break;
case IF_TYPE_IEEE1394:
printf("IEEE 1394 Firewire/n");
break;
default:
printf("Unknown type %ld/n", pIfRow->dwType);
break;
}
printf("/tMtu[%d]:/t/t %ld/n", i, pIfRow->dwMtu);
printf("/tSpeed[%d]:/t %ld/n", i, pIfRow->dwSpeed);
printf("/tPhysical Addr:/t ");
if (pIfRow->dwPhysAddrLen == 0)
printf("/n");
for (j = 0; j < (int) pIfRow->dwPhysAddrLen; j ) {
if (j == (pIfRow->dwPhysAddrLen - 1))
printf("%.2X/n", (int) pIfRow->bPhysAddr[j]);
else
printf("%.2X-", (int) pIfRow->bPhysAddr[j]);
}
printf("/tAdmin Status[%d]:/t %ld/n", i, pIfRow->dwAdminStatus);
printf("/tOper Status[%d]:/t ", i);
switch (pIfRow->dwOperStatus) {
case IF_OPER_STATUS_NON_OPERATIONAL:
printf("Non Operational/n");
break;
case IF_OPER_STATUS_UNREACHABLE:
printf("Unreachable/n");
break;
case IF_OPER_STATUS_DISCONNECTED:
printf("Disconnected/n");
break;
case IF_OPER_STATUS_CONNECTING:
printf("Connecting/n");
break;
case IF_OPER_STATUS_CONNECTED:
printf("Connected/n");
break;
case IF_OPER_STATUS_OPERATIONAL:
printf("Operational/n");
break;
default:
printf("Unknown status %ld/n", pIfRow->dwAdminStatus);
break;
}
printf("/n");
}
} else {
printf("GetIfTable failed with error: /n", dwRetVal);
if (pIfTable != NULL) {
FREE(pIfTable);
pIfTable = NULL;
}
return 1;
// Here you can use FormatMessage to find out why
// it failed.
}
if (pIfTable != NULL) {
FREE(pIfTable);
pIfTable = NULL;
}
return 0;
}


 


网友回复:mark
网友回复:mark
up
网友回复:操作系统应该提供了API,查查肯定有的!
网友回复:学习
up
网友回复:6楼的方法不错,学习了
网友回复:多谢各位大虾!
明天验证一下,满足要求给分。
不过6楼的方法中好像仅能获取速度,那双工还是半双工,是否自适应如何得到?


本篇文章来源于 www.itzhe.cn IT者网站  原文链接:http://www.itzhe.cn/news/20081005/244468.html

本文转自
http://www.itzhe.cn/news/20081005/244468.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值