首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

怎么获取网卡的状态信息

2012-05-22 
如何获取网卡的状态信息在网上找到了如何禁止核启用网卡的代码,但类似的函数中没有如何获取硬件状态的方法

如何获取网卡的状态信息
在网上找到了如何禁止核启用网卡的代码,但类似的函数中没有如何获取硬件状态的方法
SetupDiSetClassInstallParams()可以设置硬件的状态参数,但如何获取呢?
我是想列举出电脑上的多个网卡,并得到他们的状态(启用合适禁用),然后再根据自己的要求进行设置



[解决办法]
获得网卡 信息, 你指的是那些 内容?
[解决办法]
MAC地址:
http://www.codeproject.com/KB/IP/Net_Adapter_Info_in_C_.aspx
[解决办法]
using System.Net;
然后用dns 类下面可以得到。或者sever 类下
[解决办法]
我比较了一下enable状态和disable状态的HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\****下面得键值

NTEContextList在enable时时2或者3
而在disable状态下是空值
[解决办法]
路过
[解决办法]
#include "StdAfx.h"
#include <iostream>
#include <string.h>
#include "Iphlpapi.h"
#include "mac2.h"
#include <afx.h>
using namespace std;


PIP_ADAPTER_INFO pinfo=NULL;
unsigned long len=0;

CString macaddress;
CString description;
CString type;
CString subnet;
CString IpAddress;
CString gateway;
CString PrimaryWinsServer;
CString dhcp;

void GetInfo();
void ParseData();
void OutPut(CString str);

/*
void main()
{


cout<<"------------------------网卡信息检测---------------------n";
GetInfo();

}
*/

void GetInfo()
{
if (pinfo!=NULL)
delete (pinfo);
unsigned long nError;
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
if (nError==ERROR_NO_DATA)
{
OutPut("没有网络设备信息");
}
if (nError==ERROR_NOT_SUPPORTED)
{
OutPut("GetAdaptersInfo不支持本系统");
}
if (nError==ERROR_BUFFER_OVERFLOW)
{
pinfo= (PIP_ADAPTER_INFO)malloc(len);
nError = GetAdaptersInfo(pinfo,&len);
if (nError==0)
{
ParseData();
}
}

return;
}
void ParseData()
{

if (pinfo!=NULL)
{
macaddress.Format("%02X:%02X:%02X:%02X:%02X:%02X",pinfo->Address[0],pinfo->Address[1],pinfo->Address[2],pinfo->Address[3],pinfo->Address[4],pinfo->Address[5]);
description = pinfo->Description;
type.Format("%d",pinfo->Type);

PIP_ADDR_STRING pAddressList = &(pinfo->IpAddressList);
IpAddress ="";
do 
{
IpAddress += pAddressList->IpAddress.String;
pAddressList = pAddressList->Next;
if (pAddressList != NULL)
IpAddress +="rn";
} while (pAddressList != NULL);

subnet.Format("%s",pinfo->IpAddressList.IpMask.String);
gateway.Format("%s",pinfo->GatewayList.IpAddress.String);
if (pinfo->HaveWins) 
PrimaryWinsServer.Format("%s",pinfo->PrimaryWinsServer.IpAddress.String );
else
PrimaryWinsServer.Format("%s","N/A" );
if (pinfo->DhcpEnabled )
dhcp.Format("%s",pinfo->DhcpServer.IpAddress.String );
else
dhcp.Format("%s","N/A");
pinfo = pinfo->Next;


}
OutPut("网络设备为:t"+description);
OutPut("Mac地址为:t"+macaddress);
OutPut("网卡类型:t"+type); 
OutPut("IP地址:t"+IpAddress);
OutPut("子网掩码:t"+subnet);
OutPut("网关:t"+gateway);
OutPut("主Wins服务器:t"+PrimaryWinsServer);
OutPut("dhcp服务器:t"+dhcp);




}

void OutPut(CString str)
{
cout<<str.GetBuffer(str.GetLength()) <<endl;
}

[解决办法]
看看,都很有想法啊

热点排行