005
12.01.2006, 10:18 Uhr
mutche
|
Schau dir mal den folgenden Code an, damit kannst du alle Daten für einen Netzwerkadapter auslesen.
den Hostnamen hast du ja schon :-)
Gruss
C++: |
BOOL xxxyyyzzz::GetAdapterData() { BOOL bResult = FALSE; PIP_ADAPTER_INFO pAdapterInfo = NULL; PIP_ADAPTER_INFO pAdapter = NULL; unsigned long ulOutBufferLength = sizeof(IP_ADAPTER_INFO); pAdapterInfo = (PIP_ADAPTER_INFO) malloc( ulOutBufferLength/*sizeof(IP_ADAPTER_INFO)*/ ); // Make an initial call to GetAdaptersInfo to get // the necessary size into the ulOutBufLen variable if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo( pAdapterInfo, &ulOutBufferLength)) { //freigeben den vorher allocierten speichers free(pAdapterInfo); //belegen des specher mit Länge anhand der Adapteranzahl pAdapterInfo = (PIP_ADAPTER_INFO) malloc (ulOutBufferLength); int iError= 0; iError = GetAdaptersInfo( pAdapterInfo, &ulOutBufferLength);
switch(iError) { case ERROR_NO_DATA: { AfxMessageBox("No adapter information exists for the local computer"); break; } case ERROR_NOT_SUPPORTED: { AfxMessageBox("GetAdaptersInfo is not supported by the operating system running on the local computer"); break; } case ERROR_BUFFER_OVERFLOW: { AfxMessageBox("Memory Error: ERROR_BUFFER_OVERFLOW"); break; } default: { break; } }//end switch bResult = TRUE; } BOOL erg =GetHostName(); /*BOOL erg2 =m_Adapter->IsEmpty(); if( erg2 != TRUE && bResult == TRUE && erg == TRUE) { m_Adapter->RemoveAll(); }*/ POSITION Pos = m_Adapter.GetHeadPosition(); pAdapter = pAdapterInfo; do { m_AdapterData.m_strDescription.Format("%s",pAdapter->Description); //Description; //DHCP Controller if(pAdapter->DhcpEnabled) { m_AdapterData.m_strDHCP.Format("%s", pAdapter->DhcpServer.IpAddress.String); } else { m_AdapterData.m_strDHCP="N/A"; } //Standart Gateway m_AdapterData.m_strGateway.Format("%s",pAdapter->GatewayList.IpAddress.String); //Secondary Gateway //m_AdapterData->m_strGateway2 = pAdapterInfo->GatewayList.next; //m_AdapterData->m_strGateway2 = pAdapterInfo->GatewayList.IpAddress //IP-Adresse m_AdapterData.m_strIpAdress.Format("%s",pAdapter->IpAddressList.IpAddress.String); //Mac Addresse in String m_AdapterData.m_strMacAddress.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]); //IP-maske m_AdapterData.m_strSubnetMask.Format("%s",pAdapter->IpAddressList.IpMask.String); //NetType m_AdapterData.m_strType= pAdapter->Type; m_Adapter.AddTail( m_AdapterData); pAdapter = pAdapter->Next; }while(NULL != pAdapter); return bResult; }
|
|