1.Netbios方法
2.GetAdapterAddresses() 方法 (Microsoft使用的 )
#include
#include
#include
#include
#include
using namespace std; #pragma comment(lib,"IPHLPAPI.lib") #include
#include
#pragma comment(lib, "netapi32.lib") bool GetMAC( string& strMac ); //Netbios方法 bool GetMacInfo( string& strMac ); //GetAdaptersAddresses() int main(int argc, char* argv[]) { cout<<"The MAC address is:"<
Length<
IfIndex<
PhysicalAddressLength<
PhysicalAddressLength ) { memcpy(s, pInfo->PhysicalAddress, 6); printf("%02X-%02X-%02X-%02X-%02X-%02X\n", s[0], s[1], s[2], s[3], s[4], s[5]); } pInfo = pInfo->Next; //sprintf(chMac, "%02X-%02X-%02X-%02X-%02X-%02X", s[0], s[1], s[2], s[3], s[4], s[5]); } //string strMac; //cout<<"chMacLen:"<
<