• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

如何获取本机所有MAC地址

发布: 2007-7-01 20:40 | 作者: admin | 来源: | 查看: 404次 | 进入软件测试论坛讨论

领测软件测试网

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

}

 

 


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网