?? 新建 文本文檔 (3).txt
字號(hào):
#include \"stdafx.h\"
#include < windows.h >
#include < wincon.h >
#include < stdlib.h >
#include < stdio.h >
#include < time.h >
---- // 因?yàn)槭峭ㄟ^NetAPI來獲取網(wǎng)卡信息,所以需要包含其題頭文件nb30.h #include < nb30.h >
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;
ASTAT Adapter;
---- // 定義一個(gè)存放返回網(wǎng)卡信息的變量
---- // 輸入?yún)?shù):lana_num為網(wǎng)卡編號(hào),一般地,從0開始,但在Windows 2000中并不一定是連續(xù)分配的
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;
// 指定網(wǎng)卡號(hào)
---- // 首先對(duì)選定的網(wǎng)卡發(fā)送一個(gè)NCBRESET命令,以便進(jìn)行初始化
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; // 指定網(wǎng)卡號(hào)
strcpy( (char *)ncb.ncb_callname,
\"* \" );
ncb.ncb_buffer = (unsigned char *) &Adapter;
---- // 指定返回的信息存放的變量
ncb.ncb_length = sizeof(Adapter);
---- // 接著,可以發(fā)送NCBASTAT命令以獲取網(wǎng)卡的信息
uRetCode = Netbios( &ncb );
printf( \"The NCBASTAT
return code is: 0x%x \\n\", uRetCode );
if ( uRetCode == 0 )
{
---- // 把網(wǎng)卡MAC地址格式化成常用的16進(jìn)制形式,如0010-A4E4-5802
printf( \"The Ethernet Number[%d] [Page]
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);
---- // 向網(wǎng)卡發(fā)送NCBENUM命令,以獲取當(dāng)前機(jī)器的網(wǎng)卡信息,如有多少個(gè)網(wǎng)卡、每張網(wǎng)卡的編號(hào)等
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);
---- // 對(duì)每一張網(wǎng)卡,以其網(wǎng)卡編號(hào)為輸入編號(hào),獲取其MAC地址
for ( int i=0; i< lana_enum.length; ++i)
getmac_one( lana_enum.lana[i]);
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -