c++ 如何获取本机mac
展开全部
C++获取mac地址的代码:
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/*
Dev C++ -> include libnetapi32.a
BCC 5.5 or VC++ -> #pragma comment(lib,"netapi32.lib")
*/
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, *PASTAT;
void getMac(char * mac)
{
ASTAT Adapter;
NCB Ncb;
UCHAR uRetCode;
LANA_ENUM lenum;
int i = 0;
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 adapter number is: %d \n ", lenum.length);
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 );
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 );
if (uRetCode == 0)
{
//sprintf(mac, "%02x-%02x-%02x-%02x-%02x-%02x ",
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]
);
//printf( "The Ethernet Number on LANA %d is: %s\n ", lenum.lana[i], mac);
}
}
}
int main(int argc, char *argv[])
{
char *mac=new char[32];
getMac(mac);
printf( "%s\n ", mac);
delete[]mac;
system( "PAUSE> NUL ");
return 0;
}
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/*
Dev C++ -> include libnetapi32.a
BCC 5.5 or VC++ -> #pragma comment(lib,"netapi32.lib")
*/
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER NameBuff [30];
} ASTAT, *PASTAT;
void getMac(char * mac)
{
ASTAT Adapter;
NCB Ncb;
UCHAR uRetCode;
LANA_ENUM lenum;
int i = 0;
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 adapter number is: %d \n ", lenum.length);
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 );
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 );
if (uRetCode == 0)
{
//sprintf(mac, "%02x-%02x-%02x-%02x-%02x-%02x ",
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]
);
//printf( "The Ethernet Number on LANA %d is: %s\n ", lenum.lana[i], mac);
}
}
}
int main(int argc, char *argv[])
{
char *mac=new char[32];
getMac(mac);
printf( "%s\n ", mac);
delete[]mac;
system( "PAUSE> NUL ");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
快又稳
2024-10-28 广告
2024-10-28 广告
在Linux环境下配置基于域名的虚拟主机,需安装Apache或Nginx等Web服务器,并编辑配置文件。以Apache为例,需创建虚拟主机配置文件,指定域名、文档根目录等,然后启用该配置文件并重启Apache服务。同样,Nginx也需在相应...
点击进入详情页
本回答由快又稳提供
展开全部
http://blog.csdn.net/pamchen/article/details/7864072
博客写了很清楚
你也可以自己搜索:C++ 获取本机MAC地址;或者一些模拟发送包接收包的程序;或者以太网数据包解析程序,这些都会用到获取本机MAC;有不同方式
博客写了很清楚
你也可以自己搜索:C++ 获取本机MAC地址;或者一些模拟发送包接收包的程序;或者以太网数据包解析程序,这些都会用到获取本机MAC;有不同方式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询