如何获取本机所有MAC地址

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

// need include file: #include <Nb30.h><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

}

 

 

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: VC和VC++
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭