asm, c, c++ are my all
-- Core In Computer
posts - 139,  comments - 123,  trackbacks - 0

[转]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-10 16:59 Jerry Cat 阅读(567) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2006年10月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿(7)

随笔档案

最新随笔

搜索

  •  

最新评论

阅读排行榜

评论排行榜