R
Since no one wanted to help, jacked his bike and put it here to help others, perhaps the code is wrong, only checked on their system:#pragma comment(lib, "IPHLPAPI.lib")
#include <winsock2.h>
#include <iphlpapi.h>
#include <algorithm>
#include <sstream>
#include <iomanip>
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
template<typename T>
static std::string HexToString(T uval)
{
std::stringstream ss;
ss << std::setw(sizeof(uval) * 2) << std::setfill('0') << std::hex << +uval;
std::string strToConvert = ss.str();
std::transform(strToConvert.begin(), strToConvert.end(), strToConvert.begin(), ::toupper);
return strToConvert;
}
std::wstring GetMac()
{
std::wstring result;
unsigned int i = 0;
DWORD dwRetVal = 0;
ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
ULONG family = AF_INET;
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
ULONG outBufLen = sizeof(IP_ADAPTER_ADDRESSES);
pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
if (GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen) == ERROR_BUFFER_OVERFLOW)
{
FREE(pAddresses);
pAddresses = (IP_ADAPTER_ADDRESSES *)MALLOC(outBufLen);
}
if (pAddresses == NULL)
return L"";
dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen);
if (dwRetVal == NO_ERROR)
{
if (pAddresses->PhysicalAddressLength != 0)
{
std::string str;
for (i = 0; i < pAddresses->PhysicalAddressLength; i++)
{
if (i == (pAddresses->PhysicalAddressLength - 1))
str += HexToString((unsigned char)pAddresses->PhysicalAddress[i]);
else
str += HexToString((unsigned char)pAddresses->PhysicalAddress[i]) + ":";
}
result = std::wstring(str.begin(), str.end());
}
}
FREE(pAddresses);
return result;
}
p.s. from version NetBios refused because of his absence Windows Vista♪ Windows Server 2008 I'm sorry.