能力值:
( LV9,RANK:160 )
|
-
-
2 楼
http://www.upsdn.net/html/2005-01/327.html
第一种不是读取注册表来获取的,是给驱动发送消息来获取的……应该满足楼主的要求
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
#include "stdafx.h"
#include <windows.h>
//#include <iptypes.h>
#include <iphlpapi.h>
#include <NtDDNdis.h>
#pragma comment ( lib, "iphlpapi.lib" )
BOOL WINAPI GetPhyMacAddress(char* strServiceName)
{
BOOL bRet = FALSE;
char pstrBuf[512];
sprintf(pstrBuf, "//./%s", strServiceName);
HANDLE hDev = CreateFile(pstrBuf, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if ( hDev != INVALID_HANDLE_VALUE )
{
int inBuf;
BYTE outBuf[256] = { 0 };
DWORD BytesReturned;
inBuf = OID_802_3_PERMANENT_ADDRESS;
if ( DeviceIoControl(hDev, IOCTL_NDIS_QUERY_GLOBAL_STATS, (LPVOID)&inBuf, 4, outBuf, 256, &BytesReturned, NULL) )
{
sprintf(pstrBuf, "物理mac:%02X-%02X-%02X-%02X-%02X-%02X\n",
outBuf[0], outBuf[1], outBuf[2], outBuf[3], outBuf[4], outBuf[5]);
printf(pstrBuf);
bRet = TRUE;
}
inBuf = OID_802_3_CURRENT_ADDRESS;
if ( DeviceIoControl(hDev, IOCTL_NDIS_QUERY_GLOBAL_STATS, (LPVOID)&inBuf, 4, outBuf, 256, &BytesReturned, NULL) )
{
sprintf(pstrBuf, "当前mac:%02X-%02X-%02X-%02X-%02X-%02X\n",
outBuf[0], outBuf[1], outBuf[2], outBuf[3], outBuf[4], outBuf[5]);
printf(pstrBuf);
bRet = TRUE;
}
CloseHandle(hDev);
}
return bRet;
}
// 网卡 MAC 地址
BOOL GetMacAddress()
{
UINT uErrorCode = 0;
IP_ADAPTER_INFO iai;
ULONG uSize = 0;
DWORD dwResult = GetAdaptersInfo(&iai, &uSize);
if ( dwResult == ERROR_BUFFER_OVERFLOW )
{
PIP_ADAPTER_INFO piai = (PIP_ADAPTER_INFO)new BYTE[uSize];
dwResult = GetAdaptersInfo(piai, &uSize);
if ( ERROR_SUCCESS == dwResult )
{
while ( piai )
{
printf("名称:%s\n", piai->AdapterName);
printf("描述:%s\n", piai->Description);
printf("类型:%d\n", piai->Type);
GetPhyMacAddress(piai->AdapterName);
printf("\n");
piai = piai->Next;
}
}
delete[] piai;
}
return TRUE;
}
|
能力值:
( LV3,RANK:20 )
|
-
-
4 楼
感谢上面两位了,但我照上面的代码编译后获得的真实MAC为00-00-00-00-00-00,当前MAC是正确的。是怎么回事啊??
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
噢 可能你的网卡不支持那个io``我这里测试正常
|
能力值:
( LV3,RANK:20 )
|
-
-
6 楼
那有网卡不支持怎么办啊??
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
..没办法..
|
能力值:
( LV3,RANK:20 )
|
-
-
8 楼
我找到原因了,当我在注册表上修改了MAC后,他就变成全部0了。当我把那个值删掉又正常了。我在几台机子上都试过了。谢谢两位了!!!
|