求在没连网下,获取MAC地址,最好是api类,快速的那种

解决方案 »

  1.   

    网上方法大把的。 百度搜“vb  api获得MAC地址”http://blog.csdn.net/bodybo/article/details/5768422最简单的办法通过调用cmd命令GetMAC,获得控制台返回结果的可以使用命令管道。
      

  2.   

    不要cmd的,这些我都知道,网上都是在联网状态下才能得到,并且为第一网卡,也不要全部都显示的,想只得到有线网卡
      

  3.   


    我得到接近我想法的代码有问题,能帮我看一下嘛,
    Option Explicit
    Private Declare Function GetNetworkParams Lib "iphlpapi.dll" (FixedInfo As Any, pOutBufLen As Long) As Long
    'Declare Function GetIfTable Lib "iphlpapi.dll" (ByRef pIfTable As MIB_IFTABLE, ByRef pdwSize As Long, _
    '                                                ByVal bOrder As Long) As Long
    Private Declare Function GetIfTable Lib "IPHlpApi" (ByRef pIfTable As Any, ByRef pdwSize As Long, ByVal bOrder As Long) As Long
    'Declare Function GetIfEntry Lib "iphlpapi.dll" (pIfRow As MIB_IFROW) As Long
    Private Declare Function GetIfEntry Lib "iphlpapi.dll" (pIfRow As Any) As Long
        
    Private Type MIB_IFROW        '保存結果信息
         wszName(0 To 511) As Byte '接口名稱的Unicode字符串,必須為512字節
         dwIndex           As Long '接口編號
         dwType            As Long '接口類型,參看IP_ADAPTER_INFO類型的Type成員
         dwMtu             As Long '最大傳輸單元
         dwSpeed           As Long '接口速度(字節)
         dwPhysAddrLen     As Long '由bPhysAddr獲得的物理地址有效長度
         bPhysAddr(0 To 7) As Byte '物理地址
         dwAdminStatus     As Long '接口管理狀態
         dwOperStatus      As Long '操作狀態,以下值之一:
         dwLastChange      As Long '操作狀態最后改變的時間
         dwInOctets        As Long '總共收到(字節)
         dwInUcastPkts     As Long '總共收到(unicast包)
         dwInNUcastPkts    As Long '總共收到(non-unicast包),包括廣播包和多點傳送包
         dwInDiscards      As Long '收到后丟棄包總數(即使沒有錯誤)
         dwInErrors        As Long '收到出錯包總數
         dwInUnknownProtos As Long '收到后因協議不明而丟棄的包總數
         dwOutOctets       As Long '總共發送(字節)
         dwOutUcastPkts    As Long '總共發送(unicast包)
         dwOutNUcastPkts   As Long '總共發送(non-unicast包),包括廣播包和多點傳送包
         dwOutDiscards     As Long '發送丟棄包總數(即使沒有錯誤)
         dwOutErrors       As Long '發送出錯包總數
         dwOutQLen         As Long '發送隊列長度
         dwDescrLen        As Long 'bDescr部分有效長度
         bDescr(0 To 255)  As Byte '接口描述
    End TypePrivate Type MIB_IFTABLE      '包含結果表
         dwNumEntries As Long        '當前网絡接口的總數
         MIB_Table(9) As MIB_IFROW   '指向一個包含MIB_IFROW類型的指針
    End TypeSub Test()
        Dim Net As MIB_IFTABLE
        Dim LenIfT As Long
        Dim RValue As Long
        Dim I As Long
        Dim XI As Long
        Dim TXX As String
        
        LenIfT = Len(Net)
        RValue = GetIfTable(Net, LenIfT, True)
        '由Net.dwNumEntries獲得接口數量,然后用for…next循環獲取每個接口信息:
        For I = 1 To Net.dwNumEntries - 1
           With Net.MIB_Table(I)
                Debug.Print
                Debug.Print "----" & Time & "----"              Debug.Print "接口名称:" & StrConv(.wszName, vbUnicode)
                 Debug.Print "接口描述:" & StrConv(.bDescr, vbUnicode)
                Debug.Print "接口編號:" & .dwIndex
                Debug.Print "接口速度:" & .dwSpeed
                Debug.Print "接口狀態:" & .dwAdminStatus
                Debug.Print "操作狀態:" & .dwOperStatus
                Debug.Print "收到字節:" & .dwInOctets
                For XI = 1 To .dwPhysAddrLen - 1
                    TXX = TXX & Format(Hex(.bPhysAddr(XI)), "00")
                Next
                If TXX <> "" Then Debug.Print "网卡地址:"; TXX
           End With
        Next
    End SubPrivate Sub Command1_Click()
     Test
    End Sub  输出----下午 01:41:29----
    接口名称:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
    接口描述:VMware Virtual Ethernet Adapter for VMnet8                                                                                                                                                                                                                      
    接口編號:2
    接口速度:100000000
    接口狀態:1
    操作狀態:5
    收到字節:39580119
    网卡地址:5056C00008----下午 01:41:29----
    接口名称:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
    接口描述:VMware Virtual Ethernet Adapter for VMnet1                                                                                                                                                                                                                      
    接口編號:3
    接口速度:100000000
    接口狀態:1
    操作狀態:5
    收到字節:39576163
    网卡地址:5056C000085056C00001----下午 01:41:29----
    接口名称:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
    接口描述:Intel(R) PRO/100 VE Network Connection - 数据包计划程序微型端口                                                                                                                                                                                                 
    接口編號:4
    接口速度:100000000
    接口狀態:1
    操作狀態:5
    收到字節:577268166
    网卡地址:5056C000085056C0000116767C5633
      

  4.   

    这个代码RValue 返回122,得不到如上的信息,请大家帮助调试,我的是win7系统,谢谢
      

  5.   

    用wmi没那么复杂吧?
      

  6.   

    用 C 代码写一个 DLL 比较省事。下面是说明和示例代码。To get the Media Access Control (MAC) address for an ethernet adapter programmatically, use the Netbios() NCBASTAT command and provide a "*" as the name in the NCB.ncb_CallName field. This is demonstrated in the sample code below. For computers with multiple network adapters you need to enumerate the LANA numbers and perform the NCBASTAT command on each. Even when you have a single network adapter, it is a good idea to enumerate valid LANA numbers first and perform the NCBASTAT on one of the valid LANA numbers. It is considered bad programming to hardcode the LANA number to 0. In addition, other hardware and software may be assigned their own MAC addresses. For example, a modem can have a MAC address. Also, a RAS client or server can install "dummy" network adapters that correspond to a dialup or serial connection. Normally, these MAC addresses are randomly generated. If an adapter status is called on a LANA that corresponds to one of these adapters when no connection is present, Netbios returns error 0x34 (NRC_ENVNOTDEF) even if a reset was previously performed. With the NetBEUI and IPX transports, the same information can be obtained at a command prompt by using: 
       net config workstation

    The ID given is the MAC address. The following code enumerates all LANA numbers, performs a reset (NCBREST), and an adapter status (NCBASTAT). 
       #include <windows.h>
       #include <wincon.h>
       #include <stdlib.h>
       #include <stdio.h>
       #include <time.h>   typedef struct _ASTAT_
       {      ADAPTER_STATUS adapt;
          NAME_BUFFER    NameBuff [30];   }ASTAT, * PASTAT;   ASTAT Adapter;   void main (void)
       {
          NCB Ncb;
          UCHAR uRetCode;
          char NetName[50];
          LANA_ENUM   lenum;
          int      i;      memset( &Ncb, 0, sizeof(Ncb) );
          Ncb.ncb_command = NCBENUM;
          Ncb.ncb_buffer = (UCHAR *)&lenum;
          Ncb.ncb_length = sizeof(lenum);
          uRetCode = Netbios( &Ncb );
          printf( "The NCBENUM return code is: 0x%x \n", uRetCode );      for(i=0; i < lenum.length ;i++)
          {
              memset( &Ncb, 0, sizeof(Ncb) );
              Ncb.ncb_command = NCBRESET;
              Ncb.ncb_lana_num = lenum.lana[i];          uRetCode = Netbios( &Ncb );
              printf( "The NCBRESET on LANA %d return code is: 0x%x \n",
                      lenum.lana[i], uRetCode );          memset( &Ncb, 0, sizeof (Ncb) );
              Ncb.ncb_command = NCBASTAT;
              Ncb.ncb_lana_num = lenum.lana[i];          strcpy( Ncb.ncb_callname,  "*               " );
              Ncb.ncb_buffer = (char *) &Adapter;
              Ncb.ncb_length = sizeof(Adapter);          uRetCode = Netbios( &Ncb );
              printf( "The NCBASTAT on LANA %d return code is: 0x%x \n",
                      lenum.lana[i], uRetCode );
              if ( uRetCode == 0 )
              {
                 printf( "The Ethernet Number on LANA %d is:
                         %02x%02x%02x%02x%02x%02x\n",
                lenum.lana[i],
                      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] );
              }
           }
       }
      

  7.   

    简单的方法: dos命令: ipconfig/all 即可
    不需要联网, 拔了网线也可以显示. 有图为证: