BOOL
GetPhysicalAddress()
{
BOOL bRet = FALSE;
ULONG ulSizeOfpIpAdapterAddresses = 0;
PIP_ADAPTER_ADDRESSES pIpAdapterAddresses = NULL;
ULONG ulResult = ERROR_SUCCESS;
PIP_ADAPTER_ADDRESSES pCurrentIpAdapterAddress = NULL;
ULONG i = 0;
__try
{
ulSizeOfpIpAdapterAddresses = 1;
pIpAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(ulSizeOfpIpAdapterAddresses);
if (!pIpAdapterAddresses)
{
printf("[GetPhysicalAddress] : malloc failed. (%d) \n", GetLastError());
__leave;
}
ZeroMemory(pIpAdapterAddresses, ulSizeOfpIpAdapterAddresses);
ulResult = GetAdaptersAddresses(
AF_UNSPEC,
GAA_FLAG_INCLUDE_PREFIX,
NULL,
pIpAdapterAddresses,
&ulSizeOfpIpAdapterAddresses
);
if (ulResult != ERROR_SUCCESS)
{
if (ulResult == ERROR_BUFFER_OVERFLOW)
{
if (pIpAdapterAddresses)
{
free(pIpAdapterAddresses);
pIpAda
使用GetAdaptersAddresses获取电脑所有MACAddress
最新推荐文章于 2024-06-25 13:51:29 发布
这段代码展示了如何使用C++通过GetAdaptersAddresses函数获取计算机上所有网络适配器的物理(MAC)地址。它首先分配内存,然后调用GetAdaptersAddresses进行查询,遍历结果并打印出每个适配器的友好名称、描述和物理地址。
摘要由CSDN通过智能技术生成