获取网卡的相关信息
2008-07-21 15:36
274 查看
获取网卡的相关信息
关键字:网卡,网络编程,API,GetAdaptersInfo
作者:安静 更新:2003-08-12 浏览:8052
作者姓名 安静文章原始出处 北京163社区 C版
////////////////////////////////////////////////////////////////
//运行本程序需要安装Microsoft Platform SDK .这个可以去MS下载
// http://www.microsoft.com/msdownload/platformsdk/sdkupdate/ //作者:安静
//mail: aweiken@163.com
//10:56 2002-1-31 start
//14:44 2002-2-2 fix some bug.
//////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <iostream>
#include <string.h>
#include "Iphlpapi.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); //1??üoˉêy
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]);
// 本文转自 C++Builder研究 - http://www.ccrun.com/article.asp?i=548&d=52618b 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 +="/r/n";
} 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;
}
相关文章推荐
- 通过mssql数据库来获取主机的硬件相关信息,网卡,硬盘,主板等
- 网卡MAC地址相关信息大全-2 获取网卡MAC的3个方法
- 获取磁盘相关信息以及网卡相关信息
- 获取网卡的相关信息
- 网卡MAC地址相关信息大全-4 获取远程网卡MAC地址
- 如何获取网卡MAC地址(或相关信息)
- 获取网卡相关信息
- 如何获取网卡相关信息(包括mac, ip, mask, gateway等)?---利用GetAdaptersInfo
- 通过runtime获取对象相关信息
- 使用PDH性能计数器获取CPU使用率网卡信息等
- C++ 中通过GetAdaptersInfo获取网卡配置和Ip地址信息
- java代码 调用dos的ipconfig /all 命令,获取网卡详细信息
- asp.net C#获取程序文件相关信息
- Android实现获取应用程序相关信息列表的方法
- 网络信息获取函数和网卡信息获取
- 通过WMI获取系统.进程.CPU.磁盘.分区.网卡.主板.内存.显卡.共享.键盘.鼠标等信息
- 查看网卡状况的相关信息资料整理
- OpenGL ES Shader相关API 总结【0】——获取绘制信息
- 屏幕分辨率及获取屏幕相关信息(屏幕大小,状态栏、标题栏高度)
- Android获取系统相关简单信息