VC實(shí)現(xiàn)獲取本機(jī)MAC地址的方法
更新時(shí)間:2014年07月23日 10:33:16 投稿:shichen2014
這篇文章主要介紹了VC實(shí)現(xiàn)獲取本機(jī)MAC地址的方法,需要的朋友可以參考下
本文實(shí)例采用vc6.0運(yùn)行環(huán)境,通過實(shí)例實(shí)現(xiàn)獲得MAC地址的功能。
完整的實(shí)例代碼如下:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <httpext.h>
#include <windef.h>
#include <Nb30.h>
int getMAC(char * mac)
{
NCB ncb;
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;
ASTAT Adapter;
typedef struct _LANA_ENUM
{ // le
UCHAR length;
UCHAR lana[MAX_LANA];
}LANA_ENUM ;
LANA_ENUM lana_enum;
UCHAR uRetCode;
memset(&ncb, 0, sizeof(ncb));
memset(&lana_enum, 0, sizeof(lana_enum));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&lana_enum;
ncb.ncb_length = sizeof(LANA_ENUM);
uRetCode = Netbios(&ncb);
if(uRetCode != NRC_GOODRET)
return uRetCode;
for(int lana=0; lana<lana_enum.length; lana++)
{
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_enum.lana[lana];
uRetCode = Netbios(&ncb);
if(uRetCode == NRC_GOODRET)
break;
}
if(uRetCode != NRC_GOODRET)
return uRetCode;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_enum.lana[0];
strcpy((char*)ncb.ncb_callname, "*");
ncb.ncb_buffer = (unsigned char *)&Adapter;
ncb.ncb_length = sizeof(Adapter);
uRetCode = Netbios(&ncb);
if(uRetCode != NRC_GOODRET)
return uRetCode;
sprintf(mac,"%02X-%02X-%02X-%02X-%02X-%02X",
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]
);
return 0;
}
int main(int argc, char* argv[])
{
char mac[200];
getMAC(mac);
printf(" mac : %s \n",mac);
return 0;
}
另外還需要注意:必須在project->Setting里添加庫文件“netapi32.lib”。
您可能感興趣的文章:
- VC實(shí)現(xiàn)動態(tài)菜單的創(chuàng)建方法
- VC6.0如何創(chuàng)建以及調(diào)用動態(tài)鏈接庫實(shí)例詳解
- VC++操作SQLite簡單實(shí)例
- VC++基于Dx實(shí)現(xiàn)的截圖程序示例代碼
- VC實(shí)現(xiàn)批量刪除指定文件的方法
- VC程序設(shè)計(jì)中CreateProcess用法注意事項(xiàng)
- VC6.0實(shí)現(xiàn)讀取Excel數(shù)據(jù)的方法
- VC++簡單實(shí)現(xiàn)關(guān)機(jī)、重啟計(jì)算機(jī)實(shí)例代碼
- VC MFC非模態(tài)對話框的實(shí)現(xiàn)方法
- VC動態(tài)生成菜單項(xiàng)的實(shí)現(xiàn)方法
相關(guān)文章
c++中cin/cout與scanf/printf的區(qū)別比較
這篇文章主要介紹了c++中cin/cout與scanf/printf的區(qū)別比較,需要的朋友可以參考下2017-06-06
淺析設(shè)計(jì)模式中的代理模式在C++編程中的運(yùn)用
這篇文章主要介紹了設(shè)計(jì)模式中的代理模式在C++編程中的運(yùn)用,代理模式最大的好處就是實(shí)現(xiàn)了邏輯和實(shí)現(xiàn)的徹底解耦,需要的朋友可以參考下2016-03-03
C++ boost::asio編程-域名解析詳細(xì)介紹
這篇文章主要介紹了C++ boost::asio編程-域名解析詳細(xì)介紹的相關(guān)資料,這里附有實(shí)例代碼,幫助大家學(xué)習(xí)理解這部分知識,需要的朋友可以參考下2016-11-11
VSCode添加頭文件(C/C++)的實(shí)現(xiàn)示例
這篇文章主要介紹了VSCode添加頭文件(C/C++)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Qt為exe添加ico圖片的簡單實(shí)現(xiàn)步驟
這篇文章主要給大家介紹了關(guān)于Qt為exe添加ico圖片的簡單實(shí)現(xiàn)步驟,通過文中介紹的方法可以幫助大家實(shí)現(xiàn)這個(gè)自定義exe圖標(biāo)的效果,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07

