订阅所有文章
文章搜索

高级搜索这是社么?这是顶尖最新推出的文章增强型搜索功能!
全网 本站
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> VC >> 文章正文

如何获取本机所有MAC地址

作者:eion  来源:CSDN  点击  更新:2006-12-19 7:06:47  编辑: 画王w  字体

// 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];

      &nbs

[1] [2] 下一页

  • 上一篇文章:

  • 下一篇文章:
  •      
    热门文章  
    推荐文章  
    相关文章    
     发表评论
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备05002835号