////////////////////////////////////////////////////////////////
//Run this program requires the installation of the Microsoft Platform SDK. This can go to Ms download
//http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
//Author: quiet
//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<< "------------------------network card information detection---------------------\ 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 ("No Network equipment Information");
}
if (nerror==error_not_supported)
{
OutPut ("GetAdaptersInfo does not support the system");
}
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 ("network equipment: \ t" +description);
OutPut ("MAC address: \ t" +macaddress);
OutPut ("network card type: \ t" +type);
OutPut ("IP address: \ t" +ipaddress);
OutPut ("subnet mask: \ t" +subnet);
OutPut ("Gateway: \ T" +gateway);
OutPut ("primary WINS server: \ t" +primarywinsserver);
OutPut ("DHCP server: \ t" +dhcp);
}
void OutPut (CString str)
{
Cout<<str. GetBuffer (str. GetLength ()) <<endl;
}