Chinaunix首页 | 论坛 | 博客
  • 博客访问: 18938657
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-31 11:05:07

////////////////////////////////////////////////////////////////
//运行本程序需要安装Microsoft Platform SDK .这个可以去MS
//
//作者:安静
//mail: aweiken@163.com
//10:56 2002-1-31 start
//14:44 2002-2-2 fix some bug.
//////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include
#include
#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]);
     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<}
阅读(394) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~