+ Reply to Thread
Results 1 to 2 of 2

Thread: How to get all the NIC of the machine?

  1. #1

    How to get all the NIC of the machine?

    How to get all the NIC of the machine?

  2. #2
    Following is the example:

    Code:
    void DisplayAdapterInfo(CArray<CString, CString>& strNICs)
    {
    	PIP_ADAPTER_INFO	pAdapterInfo ;
    	PIP_ADAPTER_INFO	pAdapter = NULL ;
    	DWORD				dwRetVal = 0 ;
    	
    	pAdapterInfo = (IP_ADAPTER_INFO *) HeapAlloc(GetProcessHeap(), 0, sizeof (IP_ADAPTER_INFO)) ;
    	if (pAdapterInfo == NULL)
    	{
    		return ;
    	}
    
    	ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO) ;
    	if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW)
    	{
    		HeapFree(GetProcessHeap(), 0, pAdapterInfo) ;
    		pAdapterInfo = (IP_ADAPTER_INFO *) HeapAlloc(GetProcessHeap(), 0, ulOutBufLen) ;
    		if (pAdapterInfo == NULL)
    		{
    			return ;
    		}
    	}
    	
    	if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
    	{
    		pAdapter = pAdapterInfo ;
    
    		while (pAdapter)
    		{
    			char szNICAddress[1024] = "" ;
    
    			for (UINT i = 0; i < pAdapter->AddressLength; i++)
    			{
    				char szHex[10] = "" ;
    				if (i == (pAdapter->AddressLength - 1))
    				{
    					sprintf(szHex, "%.2X", (int) pAdapter->Address[i]) ;
    				}
    				else
    				{
    					sprintf(szHex, "%.2X-", (int) pAdapter->Address[i]) ;
    				}
    
    				strcat(szNICAddress, szHex) ;
    			}
    
    
    			strNICs.Add(CString(szNICAddress)) ;
    
    			pAdapter = pAdapter->Next ;
    		}
    	
    	}
    
    	if (pAdapterInfo)
    	{
    		HeapFree(GetProcessHeap(), 0, pAdapterInfo) ;
    	}
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts