• 首页
  • 小学语文
  • 中学语文
  • 中学英语
  • 免费论文
  • 教学随笔
  • 学生作文
  • 综合考试
  • 试题教案
  • 育儿话题
  • 教学资源
  • 编程技术
  • 博客
  • 如何获取本机所有MAC地址

    日期:2003-03-02  地址:  作者:

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

    }

     

     

    对 如何获取本机所有MAC地址 文章的评论    [查看网友评论]

    验证码:
    匿名发表: