VC 获取网卡信息

#include "stdafx.h"
#include <stdio.h>
#include <Windows.h>
#include <Iphlpapi.h>
#pragma comment (lib, "Iphlpapi")
#pragma comment (lib, "ws2_32")

int main(int argc, char* argv[])
{
    PIP_ADAPTER_INFO pIpAdaptTab = NULL;
    ULONG ulLen = 0;

    GetAdaptersInfo(pIpAdaptTab, &ulLen);
    if ( ulLen == 0 )
    {
        return -1;
    }

    pIpAdaptTab = (PIP_ADAPTER_INFO)malloc(ulLen);
    if ( pIpAdaptTab == NULL )
    {
        return -1;
    }

    GetAdaptersInfo(pIpAdaptTab, &ulLen);
    PIP_ADAPTER_INFO pTmp = pIpAdaptTab;
    while ( pTmp != NULL )
    {
        printf("Adapter Name : %s \r\n", pTmp->AdapterName);
        printf("Adapter Description : %s \r\n", pTmp->Description);
        printf("Ip Address : %s \r\n", pTmp->IpAddressList.IpAddress.String);
        printf("Mac Address : %02x-%02x-%02x-%02x-%02x-%02x \r\n \r\n",
                pTmp->Address[0],
                pTmp->Address[1], 
                pTmp->Address[2], 
                pTmp->Address[3], 
                pTmp->Address[4], 
                pTmp->Address[5]);

        pTmp = pTmp->Next;
    }

    free(pIpAdaptTab);
	system("pause");

	return 0;
}

你可能感兴趣的:(VC 获取网卡信息)