VC Get system NIC list and IP address information

Source: Internet
Author: User

1#include"stdafx.h"2#include <Windows.h>3#include <IPHlpApi.h>4#include <iostream>5 #pragmaComment (lib, "IPHlpApi.lib")6 using namespacestd;7 8 BOOL getlocaladaptersinfo ()9 {Ten     //Ip_adapter_info Structural Body OnePip_adapter_info Pipadapterinfo =NULL; APipadapterinfo =NewIp_adapter_info; -  -     //Structure Size theUnsignedLongUlsize =sizeof(ip_adapter_info); -  -     //Get Adapter Information -     intNret = GetAdaptersInfo (pipadapterinfo,&ulsize); +  -     if(Error_buffer_overflow = =nret) +     { A         //Insufficient space to delete previously allocated space at delete []pipadapterinfo; -  -         //Reassign Size -Pipadapterinfo = (pip_adapter_info)NewByte[ulsize]; -  -         //Get Adapter Information inNret = GetAdaptersInfo (pipadapterinfo,&ulsize); -  to         //Get failed +         if(Error_success! =nret) -         { the             if(Pipadapterinfo! =NULL) *             { $ delete []pipadapterinfo;Panax Notoginseng             } -             returnFALSE; the         } +     } A  the     //MAC Address Information +     Charszmacaddr[ -]; -     //Assignment Pointers $Pip_adapter_info Piterater =Pipadapterinfo; $      while(Piterater) -     { -cout<<"nic Name:"<<pIterater->AdapterName<<Endl; the  -cout<<"Network card Description:"<<pIterater->Description<<Endl;Wuyi  thesprintf_s (SZMACADDR, -,"%02x-%02x-%02x-%02x-%02x-%02x", -piterater->address[0], Wupiterater->address[1], -piterater->address[2], Aboutpiterater->address[3], $piterater->address[4], -piterater->address[5]); -  -cout<<"MAC Address:"<<szMacAddr<<Endl; A  +cout<<"IP Address list:"<<endl<<Endl; the  -         //point to IP Address list $Pip_addr_string pipaddr = &pIterater->ipaddresslist; the          while(PIPADDR) the         { thecout<<"IP Address:"<<pIpAddr->IpAddress.String<<Endl; thecout<<"Subnet Mask:"<<pIpAddr->IpMask.String<<Endl; -  in             //point to Gateway list thePip_addr_string pgateawaylist = &pIterater->gatewaylist; the              while(pgateawaylist) About             { thecout<<"Gateway:"<<pGateAwayList->IpAddress.String<<Endl; the  thePgateawaylist = pgateawaylist->Next; +             } -  thePIPADDR = pipaddr->Next;Bayi         } thecout<<endl<<"--------------------------------------------------"<<Endl; the  -Piterater = piterater->Next; -     } the  the     //Clean up the     if(Pipadapterinfo) the     { - delete []pipadapterinfo; the     } the  the     returnTRUE;94 } the  the int_tmain (intARGC, _tchar*argv[]) the {98 getlocaladaptersinfo (); About  -Cin.Get();101     return 0;102}


Original address: http://blog.csdn.net/sonsie007/article/details/8837572

VC Get system NIC list and IP address information

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.