是什么?

解决方案 »

  1.   

    /////////////////////////////////////////////////////////
    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);
      

  2.   

    这是什么呀,获得是不是CPUID呀,获得的好像是CPU的功能号呀
      

  3.   

    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;
        }
        
        // 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;
    }
      

  4.   

    为什么我NCB Ncb;时有错误NCB undeclared identifier我包含了nb30.h在nb30.h中有NCB的定义啊
      

  5.   

    在实际的应用系统中,我们往往会需要在程序运行时获取当前机器的网卡的MAC地址,以便作为某种标识之用,如控制程序的合法性等。下文介绍如何用Microsoft VisualC++ 6.0开发这样的程序。这里采用的方法是通过Windows 9x/NT/Win2000中内置的NetApi32.DLL的功能来实现的。首先通过发送NCBENUM命令,获取网卡的数目和每张网卡的内部编号,然后对每个网卡标号发送NCBASTAT命令获取其MAC地址。注意:这里的网卡是指捆绑了NetBEIU协议的通信协议栈,可以在网卡的属性处查看到。请运行VC++,打开一个新的工程,选择创建一个Win32 Console程序,然后按下文输入代码,并请参见其中的注释:#include "stdafx.h"#include <windows.h>#include <wincon.h>#include <stdlib.h>#include <stdio.h>#include <time.h>// 因为是通过NetAPI来获取网卡信息,所以需要包含其题头文件nb30.h#include <nb30.h>typedef struct _ASTAT_{ADAPTER_STATUS adapt;NAME_BUFFERNameBuff [30];} ASTAT, * PASTAT;ASTAT Adapter;// 定义一个存放返回网卡信息的变量// 输入参数:lana_num为网卡编号,一般地,从0开始,但在Windows 2000中并不一定是连续分配的void getmac_one (int lana_num){NCB ncb;UCHAR uRetCode;memset( &ncb, 0, sizeof(ncb) );ncb.ncb_command = NCBRESET;ncb.ncb_lana_num = lana_num // 指定网卡号// 首先对选定的网卡发送一个NCBRESET命令,以便进行初始化uRetCode = Netbios( &ncb );printf( "The NCBRESET return code is: 0x%x \n", uRetCode );memset( &ncb, 0, sizeof(ncb) );ncb.ncb_command = NCBASTAT;ncb.ncb_lana_num = lana_num; // 指定网卡号strcpy((char *)ncb.ncb_callname,"*" );ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的变量ncb.ncb_length = sizeof(Adapter);// 接着,可以发送NCBASTAT命令以获取网卡的信息uRetCode = Netbios( &ncb );printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );if ( uRetCode == 0 ){// 把网卡MAC地址格式化成常用的16进制形式,如0010-A4E4-5802printf( "The Ethernet Number[%d] is: %02X%02X-%02X%02X-%02X%02X\n",lana_num,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] );}}int main(int argc, char* argv[]){NCB ncb;UCHAR uRetCode;LANA_ENUM lana_enum;memset( &ncb, 0, sizeof(ncb) );ncb.ncb_command = NCBENUM;ncb.ncb_buffer = (unsigned char *) &lana_enum;ncb.ncb_length = sizeof(lana_enum);// 向网卡发送NCBENUM命令,以获取当前机器的网卡信息,如有多少个网卡、每张网卡的编号等uRetCode = Netbios( &ncb );printf( "The NCBENUM return code is: 0x%x \n", uRetCode );if ( uRetCode == 0 ){printf( "Ethernet Count is : %d\n\n", lana_enum.length);// 对每一张网卡,以其网卡编号为输入编号,获取其MAC地址for ( int i=0; i<lana_enum.length; ++i)getmac_one( lana_enum.lana[i]);}return 0;}此时,按F7编译,按F5运行即可。这段代码可以直接嵌入相关的应用系统之中,或封装成.DLL或COM控件,以便可以在Visual Basic、Visual Foxpro、Power Builder或Delphi等其他程序中调用。