小弟用Netbios命令读取网卡的mac地址。
但是有时候网络属性里面添加了拨号协议或其他什么的,
读出的mac地址会变化,在2000,XP下,还有个地方(网卡属性、注册表中)可以修改这个
mac地址,希望各位哥哥能叫我个方法,读取真实的物理地址,不被上层软件欺骗。
(软件是运行在本计算机上的,不是通过网络的方法来读取)

解决方案 »

  1.   

    //获得mac address
    // Fetches the MAC address and prints it
    static void GetMACaddress(void)
    {
      IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information 
                                             // for up to 16 NICs
      DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
        AdapterInfo,                 // [out] buffer to receive data
        &dwBufLen);                  // [in] size of receive data buffer
      assert(dwStatus == ERROR_SUCCESS);  // Verify return value is 
                                          // valid, no buffer overflow  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
                                                   // current adapter info
      do {
        PrintMACaddress(pAdapterInfo->Address); // Print MAC address
        pAdapterInfo = pAdapterInfo->Next;    // Progress through 
                                              // linked list
      }
      while(pAdapterInfo);                    // Terminate if last adapter
    }
    //详细请见(source code ):
    http://codeguru.earthweb.com/network/GetMAC.html
    // Fetches the MAC address and prints it
    static void GetMACaddress(void)
    {
      unsigned char MACData[8];      // Allocate data structure 
                                     // for MAC (6 bytes needed)  WKSTA_TRANSPORT_INFO_0 *pwkti; // Allocate data structure 
                                     // for NetBIOS
      DWORD dwEntriesRead;
      DWORD dwTotalEntries;
      BYTE *pbBuffer;
        
      // Get MAC address via NetBIOS's enumerate function
      NET_API_STATUS dwStatus = NetWkstaTransportEnum(
       NULL,                 // [in]  server name
       0,                    // [in]  data structure to return
       &pbBuffer,            // [out] pointer to buffer
       MAX_PREFERRED_LENGTH, // [in]  maximum length
       &dwEntriesRead,       // [out] counter of elements 
                             //       actually enumerated
       &dwTotalEntries,      // [out] total number of elements 
                             //       that could be enumerated
       NULL);                // [in/out] resume handle
      assert(dwStatus == NERR_Success);  pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer; // type cast the buffer  for(DWORD i=1; i< dwEntriesRead; i++)  // first address is
                                                // 00000000, skip it
      {                                         // enumerate MACs & print
        swscanf((wchar_t *)pwkti[i].wkti0_transport_address,
                L"%2hx%2hx%2hx%2hx%2hx%2hx",
                &MACData[0],
                &MACData[1],
                &MACData[2], 
                &MACData[3],
                &MACData[4],
                &MACData[5]);
        PrintMACaddress(MACData);
      }  // Release pbBuffer allocated by above function
      dwStatus = NetApiBufferFree(pbBuffer);
      assert(dwStatus == NERR_Success);
    }
      

  2.   

    看看 fap 有专题的文章
      

  3.   

    http://community.csdn.net/Expert/topic/3160/3160135.xml?temp=.2023279
      

  4.   

    http://community.csdn.net/Expert/topic/3149/3149732.xml?temp=.7122614