如何获取本机所有MAC地址
2004-02-26 10:51
621 查看
// need include file: #include <Nb30.h>
// need libary: Netapi32.lib
int GetAllLocalAdapterMacAddr(std::list<std::vector<unsigned char> >& mac)
{
NCB ncb;
LANA_ENUM AdapterList;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&AdapterList;
ncb.ncb_length = sizeof(AdapterList);
Netbios(&ncb);
mac.resize(0);
for (int i = 0; i < AdapterList.length ; ++i )
{
struct ASTAT
{
ADAPTER_STATUS adapt;
NAME_BUFFER psz_name[30];
} Adapter;
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset( &Ncb, 0, sizeof (Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = AdapterList.lana[i];
if (Netbios(&Ncb) != NRC_GOODRET)
continue;
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb)) ;
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = AdapterList.lana[ i ];
strcpy((char *)Ncb.ncb_callname, "*" );
memset(&Adapter, 0, sizeof (Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof (Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
if ( Netbios( &Ncb ) == 0 )
{
std::vector<unsigned char> v6;
v6.resize(6);
for (int i=0; i<6; i++)
v6[i] = Adapter.adapt.adapter_address[i];
if (v6[0] == 0)
{
std::list<std::vector<unsigned char> >::iterator i = mac.begin();
for (; i!=mac.end(); i++) if (*i == v6)
break;
if (i==mac.end())
mac.push_back(v6);
}
}
else
break;
}
return 0;
}
// need libary: Netapi32.lib
int GetAllLocalAdapterMacAddr(std::list<std::vector<unsigned char> >& mac)
{
NCB ncb;
LANA_ENUM AdapterList;
memset(&ncb, 0, sizeof(ncb));
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *)&AdapterList;
ncb.ncb_length = sizeof(AdapterList);
Netbios(&ncb);
mac.resize(0);
for (int i = 0; i < AdapterList.length ; ++i )
{
struct ASTAT
{
ADAPTER_STATUS adapt;
NAME_BUFFER psz_name[30];
} Adapter;
// Reset the LAN adapter so that we can begin querying it
NCB Ncb;
memset( &Ncb, 0, sizeof (Ncb));
Ncb.ncb_command = NCBRESET;
Ncb.ncb_lana_num = AdapterList.lana[i];
if (Netbios(&Ncb) != NRC_GOODRET)
continue;
// Prepare to get the adapter status block
memset(&Ncb, 0, sizeof(Ncb)) ;
Ncb.ncb_command = NCBASTAT;
Ncb.ncb_lana_num = AdapterList.lana[ i ];
strcpy((char *)Ncb.ncb_callname, "*" );
memset(&Adapter, 0, sizeof (Adapter));
Ncb.ncb_buffer = (unsigned char *)&Adapter;
Ncb.ncb_length = sizeof (Adapter);
// Get the adapter's info and, if this works, return it in standard,
// colon-delimited form.
if ( Netbios( &Ncb ) == 0 )
{
std::vector<unsigned char> v6;
v6.resize(6);
for (int i=0; i<6; i++)
v6[i] = Adapter.adapt.adapter_address[i];
if (v6[0] == 0)
{
std::list<std::vector<unsigned char> >::iterator i = mac.begin();
for (; i!=mac.end(); i++) if (*i == v6)
break;
if (i==mac.end())
mac.push_back(v6);
}
}
else
break;
}
return 0;
}
相关文章推荐
- 如何在vc++中旋转位图---任意角度
- 进入博客园首页 怎么出现这种错误?不知其他人有没有???
- 今天我的Bolg正式开通啦
- >>Helpful Points on .NET Performance
- 今天突然发现blog 中滚动鼠标滑轮,可以自动放大,缩小字体,怎么做的?
- CCI project
- Office Research Service & SharePoint Services
- 丝绸与磁器
- 制造业与软件业
- 我们的软件工业
- 软件工程师
- 名牌产品的创意
- 大工业的人才
- MDA模型驱动开发方式下的分工
- 用Visual Studio .Net 2003开发PHP程序
- 首页增加了博客堂的链接
- 如何解决FreeTextBox中HTMLEncoded文本的Bug
- 看一看你的财富在整个世界的排名
- JBoss集成ColdFusion和Jetspeed
- XSLT学习笔记(一)