TanZek's 技术空间

勇往直前,专注于技术...

首页 新随笔 联系 聚合 管理
  7 Posts :: 19 Stories :: 13 Comments :: 0 Trackbacks

VC++编程获取机器的MAC地址:

NetBIOS编程篇

   #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((
char   * )Ncb.ncb_callname, " * "  );
          Ncb.ncb_buffer 
=  (unsigned  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 ]);
          }
       }
 system(
" PAUSE " );
}


所用的资料:
NetBIOS API编程,NCBENUM命令调用,ADAPTER_STATUS结构等。

 

[摘自MSDN]

ADAPTER_STATUS

The ADAPTER_STATUS structure contains information about a network adapter. This structure is pointed to by the ncb_buffer member of the NCB structure. ADAPTER_STATUS is followed by as many NAME_BUFFER structures as required to describe the network adapters on the system. 
 

typedef  struct  _ADAPTER_STATUS { 
    UCHAR   adapter_address[
6 ]; 
    UCHAR   rev_major; 
    UCHAR   reserved0; 
    UCHAR   adapter_type; 
    UCHAR   rev_minor; 
    WORD    duration; 
    WORD    frmr_recv; 
    WORD    frmr_xmit; 
    WORD    iframe_recv_err; 
    WORD    xmit_aborts; 
    DWORD   xmit_success; 
    DWORD   recv_success; 
    WORD    iframe_xmit_err; 
    WORD    recv_buff_unavail; 
    WORD    t1_timeouts; 
    WORD    ti_timeouts; 
    DWORD   reserved1; 
    WORD    free_ncbs; 
    WORD    max_cfg_ncbs; 
    WORD    max_ncbs; 
    WORD    xmit_buf_unavail; 
    WORD    max_dgram_size; 
    WORD    pending_sess; 
    WORD    max_cfg_sess; 
    WORD    max_sess; 
    WORD    max_sess_pkt_size; 
    WORD    name_count; 
} ADAPTER_STATUS, 
* PADAPTER_STATUS;

 

Members

adapter_address
Specifies encoded address of the adapter.
rev_major
Specifies the major software-release level. This value is 3 for IBM NetBIOS 3. x.
reserved0
Reserved. This value is always zero.
adapter_type
Specifies the adapter type. This value is 0xFF for a Token Ring adapter or 0xFE for an Ethernet adapter.
rev_minor
Specifies the minor software-release level. This value is zero for IBM NetBIOS x.0.
duration
Specifies the duration of the reporting period, in minutes.
frmr_recv
Specifies the number of FRMR frames received.
frmr_xmit
Specifies the number of FRMR frames transmitted.
iframe_recv_err
Specifies the number of I frames received in error.
xmit_aborts
Specifies the number of aborted transmissions.
xmit_success
Specifies the number of successfully transmitted packets.
recv_success
Specifies the number of successfully received packets.
iframe_xmit_err
Specifies the number of I frames transmitted in error.
recv_buff_unavail
Specifies the number of times a buffer was not available to service a request from a remote computer.
t1_timeouts
Specifies the number of times that the DLC T1 timer timed out.

Windows XP  DLC will no longer be supported. For more information, see Network Protocol Support in Windows.

ti_timeouts
Specifies the number of times that the ti inactivity timer timed out. The ti timer is used to detect links that have been broken.
reserved1
Reserved. This value is always zero.
free_ncbs
Specifies the current number of free network control blocks.
max_cfg_ncbs
Undefined for IBM NetBIOS 3.0.
max_ncbs
Undefined for IBM NetBIOS 3.0.
xmit_buf_unavail
Undefined for IBM NetBIOS 3.0.
max_dgram_size
Specifies the maximum size of a datagram packet. This value is always at least 512 bytes.
pending_sess
Specifies the number of pending sessions.
max_cfg_sess
Specifies the configured maximum pending sessions.
max_sess
Undefined for IBM NetBIOS 3.0.
max_sess_pkt_size
Specifies the maximum size of a session data packet.
name_count
Specifies the number of names in the local names table.

Requirements

  Windows NT/2000/XP: Included in Windows NT 3.1 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Nb30.h.

posted on 2006-10-09 19:38 TanZek 阅读(4991) 评论(2)  编辑 收藏 引用

评论

# re: VC++编程获取机器的MAC地址 2007-11-07 10:59 queniao
此 例程 只能 获取有线网卡的MAC地址,对与无线网卡 无能为力   回复  更多评论
  

# re: VC++编程获取机器的MAC地址 2016-07-29 07:48 www.daohangweike.com
www.listal.com/list/-cqfp
www.listal.com/list/-cdkp
www.listal.com/list/-whfp
www.listal.com/list/-hffp
www.listal.com/list/-syfp
www.listal.com/list/-jnfp
www.listal.com/list/-ccfp
www.listal.com/list/-shfp
www.listal.com/list/-bjfp
www.listal.com/list/-csfp
www.listal.com/list/-gzfp
www.listal.com/list/-szfp
www.listal.com/list/-hzfp
www.listal.com/list/-njkp
www.listal.com/list/-tjjfp
www.listal.com/list/-nbfp
www.listal.com/list/-fzfp
www.listal.com/list/-sjzfp
www.listal.com/list/-hebfp
www.listal.com/list/-qdfp
www.listal.com/list/-sufp
www.listal.com/list/-wxfp
www.listal.com/list/-zzfp
www.listal.com/list/-kmfp
www.listal.com/list/-xafp
www.listal.com/list/-lzfp
www.listal.com/list/-gyfp
www.listal.com/list/-nnfp
www.listal.com/list/-xmfp

www.listal.com/list/-cqkaifp
www.listal.com/list/-cqkafp
www.listal.com/list/-whkaifp
www.listal.com/list/-hefkaifp
www.listal.com/list/-sydkaifp
www.listal.com/list/-jndkaifp
www.listal.com/list/-ccdkaifp
www.listal.com/list/-shhkaifp
www.listal.com/list/-bjdkaifp
www.listal.com/list/-ncdkaifp
www.listal.com/list/-csdkaifp
www.listal.com/list/-gzkp
www.listal.com/list/-szkp
www.listal.com/list/-hzkp
www.listal.com/list/-njkaip
www.listal.com/list/-tjkp
www.listal.com/list/-nbkp
www.listal.com/list/-fzkp
www.listal.com/list/-sjzkp
www.listal.com/list/-hebkp
www.listal.com/list/-qdkp
www.listal.com/list/-sukp
www.listal.com/list/-wxkp
www.listal.com/list/-zzkp
www.listal.com/list/-kmkp
www.listal.com/list/-xakp
www.listal.com/list/-lzkp
www.listal.com/list/-nnkp
www.listal.com/list/-gykp
www.listal.com/list/-xmkp
www.listal.com/list/-dgkp
www.listal.com/list/-fskp
www.listal.com/list/-ytkp
www.listal.com/list/-wzkp
www.listal.com/list/-bdkp
www.listal.com/list/-zskp
www.listal.com/list/-tykp
www.listal.com/list/-dlkp
www.listal.com/list/-hkkp
www.listal.com/list/-tskp
www.listal.com/list/-zhkp
www.listal.com/list/-huikp
www.listal.com/list/-ntkp
www.listal.com/list/-xnkp
www.listal.com/list/-cqkp
www.listal.com/list/-cdkaip
www.listal.com/list/-whkp
www.listal.com/list/-hfkp
www.listal.com/list/-sykp
www.listal.com/list/-jnkp
www.listal.com/list/-cckaip
www.listal.com/list/-shkp
www.listal.com/list/-bjkp
www.listal.com/list/-nckp
www.listal.com/list/-cskp

www.listal.com/list/-bjsbz
www.listal.com/list/-tjsbz
www.listal.com/list/-shsbz
www.listal.com/list/-cqsbz
www.listal.com/list/-szsbz
www.listal.com/list/-hebsbz
www.listal.com/list/-sjzsbz
www.listal.com/list/-ccsbz
www.listal.com/list/-sysbz
www.listal.com/list/-njsbz
www.listal.com/list/-hfsbz
www.listal.com/list/-jnsbz
www.listal.com/list/-zzsbz
www.listal.com/list/-whsbz
www.listal.com/list/-cssbz
www.listal.com/list/-ncsbz
www.listal.com/list/-xasbz
www.listal.com/list/-tysbz
www.listal.com/list/-cdsbz
www.listal.com/list/-gzsbz
www.listal.com/list/-gysbz
www.listal.com/list/-hzsbz
www.listal.com/list/-fzsbz
www.listal.com/list/-lzsbz
www.listal.com/list/-kmsbz
www.listal.com/list/-nnsbz
www.listal.com/list/-hksbz
www.listal.com/list/-qdsbz
www.listal.com/list/-susbz
www.listal.com/list/-nbsbz
www.listal.com/list/-wxsbz
www.listal.com/list/-ntsbz
www.listal.com/list/-xmsbz
www.listal.com/list/-cqsbzw
www.listal.com/list/-dgsbz
www.listal.com/list/-lysbz
www.listal.com/list/-xzsbz
www.listal.com/list/-lfsbz
www.listal.com/list/-xysbz
www.listal.com/list/-hdsbz
www.listal.com/list/-wzsbz
www.listal.com/list/-xnsbz
www.listal.com/list/-wfsbz
www.listal.com/list/-sxsbz
www.listal.com/list/wufbz
www.listal.com/list/qjbz
www.listal.com/list/mybz
www.listal.com/list/zzbanz
www.listal.com/list/jnbz
www.listal.com/list/weibz
www.listal.com/list/dybz
www.listal.com/list/czbz
www.listal.com/list/tabz
www.listal.com/list/zhbz
www.listal.com/list/asbz
www.listal.com/list/gzmm
www.listal.com/list/gzam
www.listal.com/list/gzsn
www.listal.com/list/gzvip
www.listal.com/list/gzxj
  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理