BOOL GetMacAddress(CStringArray& strMacArray, CString strSpecifiedIP) { PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; DWORD dwRetVal = 0; ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO); pAdapterInfo = new IP_ADAPTER_INFO[ulOutBufLen]; if (pAdapterInfo == NULL) return FALSE; if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { delete pAdapterInfo; pAdapterInfo = new IP_ADAPTER_INFO[ulOutBufLen]; if (pAdapterInfo == NULL) return FALSE; } if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) { pAdapter = pAdapterInfo; while (pAdapter) { CStringA strMacAddress; 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]); CStringA strIPAddress; strIPAddress.Format("%s", pAdapter->IpAddressList.IpAddress.String); if(strSpecifiedIP.GetLength() > 0) { if(strIPAddress.Find(CT2A(strSpecifiedIP)) >= 0) { strMacArray.Add(CA2T(strMacAddress)); break; } } else strMacArray.Add(CA2T(strMacAddress)); pAdapter = pAdapter->Next; } } delete pAdapterInfo; pAdapterInfo = NULL; return TRUE; }
00:27:88:3C:9B:E3
MAC
Retrieved from http://hyacinth.byus.net/moniwiki/wiki.php/C++/GetMacAddress
last modified 2014-10-22 11:49:58