參考例項如下,並請參見其中的註釋:
#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_BUFFER NameBuff [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 );
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命令以獲取網絡卡的資訊
printf( "The NCBASTAT
return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
---- // 把網絡卡MAC地址格式化成常用的16進位制形式,如0010-A4E4-5802
printf( "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[])
LANA_ENUM lana_enum;
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(lana_enum);
---- // 向網絡卡傳送NCBENUM命令,以獲取當前機器的網絡卡資訊,如有多少個網絡卡、每張網絡卡的編號等
printf( "The NCBENUM return
code is:
printf( "Ethernet Count is : %d\n\n", lana_enum.length);
---- // 對每一張網絡卡,以其網絡卡編號為輸入編號,獲取其MAC地址
for ( int i=0; i
getmac_one( lana_enum.lana[i]);
return 0;
/
參考例項如下,並請參見其中的註釋:
#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_BUFFER NameBuff [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-5802
printf( "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
getmac_one( lana_enum.lana[i]);
}
return 0;
}
/