본문 바로가기
C & C++/MFC Network

[IP] Lan Card 정보 추출

by izen8 2011. 4. 18.
반응형

void CTestDlg::OnButton1()
{

    CString LocalAdap;
    CString LocalMac;
    CString LocalIP;
    CString LocalSub;
    CString LocalGate;
 
    PIP_ADAPTER_INFO pAdapterInfo;
    PIP_ADAPTER_INFO pAdapter = NULL;
    DWORD dwRetVal = 0;
    BOOL m_bBreak = FALSE;
 
    pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
    unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
 
    if(GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS)
    {
        GlobalFree(pAdapterInfo);
        pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen);
    }
 
    if((dwRetVal=GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
    {
        pAdapter = pAdapterInfo;
        while(pAdapter)
        {
            LocalAdap.Format ("%s", pAdapter->Description);

            LocalMac.Format ("%02X-%02X-%02X-%02X-%02X-%02X", pAdapter->Address[0], pAdapter->Address[1],
                pAdapter->Address[2],pAdapter->Address[3], pAdapter->Address[4], pAdapter->Address[5]);
            LocalIP.Format ("%s", pAdapter->IpAddressList.IpAddress.String);
             LocalSub.Format ("%s", pAdapter->IpAddressList.IpMask.String);
 
            if(pAdapter->Next == NULL)
            {
                m_bBreak = TRUE;
                break;
            }
 
            pAdapter = pAdapter->Next;
        }
    }
    else
    {
        AfxMessageBox("Call to GetAdapterInfo failed");
    }

AfxMessageBox(LocalAdap);
AfxMessageBox(LocalMac);
AfxMessageBox(LocalIP);

AfxMessageBox(LocalSub);

}

반응형

댓글