BOOL islocaladapter (const char *padaptername)
{
BOOL ret_value = FALSE;
Char szdatabuf[max_path+1] = {0};
DWORD Dwdatalen = MAX_PATH;
DWORD dwtype = REG_SZ;
Hkey hlocalnet = NULL;
#define Net_card_key (_t ("system\\currentcontrolset\\control\\network\\{4d36e972-e325-11ce-bfc1-08002be10318}"))
sprintf (Szdatabuf, "%s\\%s\\connection", Net_card_key, Padaptername);
if (Error_success!= RegOpenKeyEx (HKEY_LOCAL_MACHINE, SZDATABUF, 0, Key_read, &hlocalnet))
{
return FALSE;
}
/* The network card information in the registry does not have this item
if (error_success!= RegQueryValueEx (hlocalnet, _t ("Mediasubtype"), 0, &dwtype, (BYTE *) Szdatabuf, &dwdatalen))
{
GOTO ret;
}
if (* (DWORD *) szdatabuf)!=0x01)
GOTO ret;
*/
Dwdatalen = MAX_PATH;
memset (szdatabuf,0,sizeof (SZDATABUF));
if (error_success!= RegQueryValueEx (hlocalnet, _t ("Pnpinstanceid"), 0, &dwtype, (BYTE *) Szdatabuf, &dwdatalen) )
{
GOTO ret;
}
if (strncmp (SZDATABUF, "PCI", strlen ("PCI"))
{
"PCI" in this key value in the network card information in the registry is not all in the front
CString id = szdatabuf;
int ret = ID. Find ("PCI");
if (ret = 1)
{
GOTO ret;
}
}
Ret_value = TRUE;
Ret:
RegCloseKey (hlocalnet);
return ret_value;
}
void macaddresstostring (const lpbyte address, LPSTR lpsz, int naddresslength = 6)
{
LPSTR p = lpsz;
for (int i = 0; i < naddresslength; i++)
{
p + + sprintf (p, I?) ":%02x": "%02x", Address[i]);
}
}
#if 1
#include "stdafx.h"
#include <atlbase.h>
#include <atlconv.h>
#include "iphlpapi.h"
#pragma comment (lib, "Iphlpapi.lib")
int Getmacbycmd (char* mac)
{
Pip_adapter_info Padapterinfo;
DWORD adapterinfosize = 0;
DWORD dwretval=0;
GetAdaptersInfo (null,&adapterinfosize);
Padapterinfo = (pip_adapter_info) GlobalAlloc (gptr,adapterinfosize);
GetAdaptersInfo (padapterinfo,&adapterinfosize);
Pip_adapter_info padapter = Padapterinfo;
while (padapter)
{
if (Islocaladapter (padapter->adaptername))
{
macaddresstostring (padapter->address,mac,padapter->addresslength);
break;
}
else
{
padapter = padapter->next;
}
&NBSP}
globalfree (padapterinfo);
return 0;
}
#endif