Get information about the NIC

Source: Internet
Author: User

////////////////////////////////////////////////////////////////


//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;


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.