GetMac 的函数 方法一、rpc #include <rpc.h> #include <iostream>#ifdef _MSC_VER using namespace std; #endifint main() { cout << "MAC address is: "; // Ask RPC to create a UUID for us. If this machine has an Ethernet // adapter, the last six bytes of the UUID (bytes 2-7 inclusive in // the Data4 element) should be the MAC address of the local // Ethernet adapter. UUID uuid; UuidCreate(&uuid); // Spit the address out for (int i = 2; i < 8; ++i) { cout << hex; cout.fill('0'); cout.width(2); cout << int (uuid.Data4[i]); if (i < 7) { cout << ":"; } } cout << endl; return 0; }方法二、 bool GetAdapterInfo(int nAdapterNum, string & sMAC) { // Reset the LAN adapter so that we can begin querying it NCB Ncb; memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = nAdapterNum; if (Netbios(&Ncb) != NRC_GOODRET) { char acTemp[80]; ostrstream outs(acTemp, sizeof(acTemp)); outs << "error " << Ncb.ncb_retcode << " on reset" << ends; sMAC = acTemp; return false; }
// Get the adapter's info and, if this works, return it in standard, // colon-delimited form. if (Netbios(&Ncb) == 0) { char acMAC[18]; sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X", int (Adapter.adapt.adapter_address[0]), int (Adapter.adapt.adapter_address[1]), int (Adapter.adapt.adapter_address[2]), int (Adapter.adapt.adapter_address[3]), int (Adapter.adapt.adapter_address[4]), int (Adapter.adapt.adapter_address[5])); sMAC = acMAC; return true; } else { char acTemp[80]; ostrstream outs(acTemp, sizeof(acTemp)); outs << "error " << Ncb.ncb_retcode << " on ASTAT" << ends; sMAC = acTemp; return false; } }int main() { // Get adapter list LANA_ENUM AdapterList; NCB Ncb; memset(&Ncb, 0, sizeof(NCB)); Ncb.ncb_command = NCBENUM; Ncb.ncb_buffer = (unsigned char *)&AdapterList; Ncb.ncb_length = sizeof(AdapterList); Netbios(&Ncb); // Get all of the local ethernet addresses string sMAC; for (int i = 0; i < AdapterList.length; ++i) { if (GetAdapterInfo(AdapterList.lana[i], sMAC)) { cout << "Adapter " << int (AdapterList.lana[i]) << "'s MAC is " << sMAC << endl; } else { cerr << "Failed to get MAC address! Do you" << endl; cerr << "have the NetBIOS protocol installed?" << endl; break; } } return 0; }
CString m_strCpuInfo;
m_strCpuInfo.Empty();
char OEMString[13];
int iEAXValue,iEBXValue,iECXValue,iEDXValue;
_asm {
mov eax,0
cpuid
mov DWORD PTR OEMString,ebx
mov DWORD PTR OEMString+4,edx
mov DWORD PTR OEMString+8,ecx
mov BYTE PTR OEMString+12,0
}
m_strCpuInfo.Format("%s",OEMString);
_asm {
mov eax,1
cpuid
mov iEAXValue,eax
mov iEBXValue,ebx
mov iECXValue,ecx
mov iEDXValue,edx
}
if(iEDXValue&0x800000)
m_strCpuInfo.Format("%s%s",m_strCpuInfo," MMX SUPPORT");
else
m_strCpuInfo.Format("%s%s",m_strCpuInfo," MMX NOT SUPPORT");
int iCPUFamily=(0xf00 & iEAXValue)>>8;
m_strCpuInfo.Format("%s%s%d",m_strCpuInfo,"\r\n Family: ",iCPUFamily);
////////////////////////////////////////////////////////////////////
//Mac Address
CString m_addr;
CString m_strT;
CString sNetBiosName;
char hostname[128];
struct hostent *phost;
gethostname(hostname,128);
m_addr = hostname;
phost = gethostbyname(hostname);
int m_iCounter=0;
for(int j = 0;j<4;j++)
{
m_strT.Format("%u", (unsigned int)((unsigned char*)phost->h_addr_list[0])[j]);
sNetBiosName+=m_strT;
if(m_iCounter<3)
{
m_iCounter++;
sNetBiosName+=".";
}
} strcpy(LocalSys.ip,sNetBiosName);
ASTAT Adapter;
NCB ncb;
UCHAR uRetCode;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = 0;
uRetCode = Netbios(&ncb);
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = 0;
sNetBiosName.MakeUpper();
FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20);
strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);
ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20;
ncb.ncb_callname[NCBNAMSZ] = 0x0;
ncb.ncb_buffer = (unsigned char *) &Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&ncb);
CString sMacAddress;
if (uRetCode == 0)
{
sMacAddress.Format(_T("%02x%02x%02x%02x%02x%02x"),
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5]);
}
strcpy(LocalSys.mac,sMacAddress);
方法一、rpc
#include <rpc.h>
#include <iostream>#ifdef _MSC_VER
using namespace std;
#endifint main()
{
cout << "MAC address is: "; // Ask RPC to create a UUID for us. If this machine has an Ethernet
// adapter, the last six bytes of the UUID (bytes 2-7 inclusive in
// the Data4 element) should be the MAC address of the local
// Ethernet adapter.
UUID uuid;
UuidCreate(&uuid); // Spit the address out
for (int i = 2; i < 8; ++i) {
cout << hex;
cout.fill('0');
cout.width(2);
cout << int (uuid.Data4[i]);
if (i < 7) {
cout << ":";
}
}
cout << endl; return 0;
}方法二、
bool GetAdapterInfo(int nAdapterNum, string & sMAC)
{
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = nAdapterNum;
if (Netbios(&Ncb) != NRC_GOODRET) {
char acTemp[80];
ostrstream outs(acTemp, sizeof(acTemp));
outs << "error " << Ncb.ncb_retcode << " on reset" << ends;
sMAC = acTemp;
return false;
}
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb));
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = nAdapterNum;
strcpy((char *) Ncb.ncb_callname, "*");
struct ASTAT {
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff[30];
} Adapter;
memset(&Adapter, 0, sizeof(Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof(Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
if (Netbios(&Ncb) == 0) {
char acMAC[18];
sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X",
int (Adapter.adapt.adapter_address[0]),
int (Adapter.adapt.adapter_address[1]),
int (Adapter.adapt.adapter_address[2]),
int (Adapter.adapt.adapter_address[3]),
int (Adapter.adapt.adapter_address[4]),
int (Adapter.adapt.adapter_address[5]));
sMAC = acMAC;
return true;
}
else {
char acTemp[80];
ostrstream outs(acTemp, sizeof(acTemp));
outs << "error " << Ncb.ncb_retcode << " on ASTAT" << ends;
sMAC = acTemp;
return false;
}
}int main()
{
// Get adapter list
LANA_ENUM AdapterList;
NCB Ncb;
memset(&Ncb, 0, sizeof(NCB));
Ncb.ncb_command = NCBENUM;
Ncb.ncb_buffer = (unsigned char *)&AdapterList;
Ncb.ncb_length = sizeof(AdapterList);
Netbios(&Ncb); // Get all of the local ethernet addresses
string sMAC;
for (int i = 0; i < AdapterList.length; ++i) {
if (GetAdapterInfo(AdapterList.lana[i], sMAC)) {
cout << "Adapter " << int (AdapterList.lana[i]) <<
"'s MAC is " << sMAC << endl;
}
else {
cerr << "Failed to get MAC address! Do you" << endl;
cerr << "have the NetBIOS protocol installed?" << endl;
break;
}
} return 0;
}