读取网卡信息IP,MAC的GetAdaptersInfo函数

#include <winsock.h>
#include <Iphlpapi.h>
#include <Nb30.h>

#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Iphlpapi.lib")
#pragma comment(lib, "Netapi32.lib")


int main()

{

    IP_ADAPTER_INFO AdapterInfo[16];            // Allocate information for up to 16 NICs
    DWORD dwBufLen = sizeof(AdapterInfo);        // Save the memory size of buffer

    DWORD dwStatus = GetAdaptersInfo(            // Call GetAdapterInfo
        AdapterInfo,                            // [out] buffer to receive data
        &dwBufLen);                                // [in] size of receive data buffer
    //assert(dwStatus == ERROR_SUCCESS);            // Verify return value is valid, no buffer overflow

    PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info

    printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
        pAdapterInfo->Address[0], pAdapterInfo->Address[1], pAdapterInfo->Address[2], pAdapterInfo->Address[3], pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
  }


你可能感兴趣的:(读取网卡信息IP,MAC的GetAdaptersInfo函数)