CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    162

    getting the MacId

    can anyone of you give me a hint on how to read the MacId(s) of my network adpter(s)???

  2. #2
    Join Date
    Jun 2002
    Location
    Letchworth, UK
    Posts
    1,020
    On what OS/Compiler? The following works on MSVC6

    Code:
    #include "stdafx.h"
    
    
    // Obtain the Media Access Control Address (MAC)
    // needs netapi32.lib
     
    #include <windows.h>
    #include <nb30.h>
    #include <stdio.h>
    #include <tchar.h>
     
    typedef struct _ASTAT_
    {
        ADAPTER_STATUS adapt;
        NAME_BUFFER    NameBuff [30];
    }ASTAT, * PASTAT;
     
    ASTAT Adapter;
     
    int _tmain(int argc, _TCHAR* argv[])
    {
        NCB ncb;
        BYTE bRetCode;
     
        memset( &ncb, 0, sizeof(ncb) );
        ncb.ncb_command = NCBRESET;
        ncb.ncb_lana_num = 0;
     
        bRetCode = Netbios( &ncb );
        _tprintf( _T("The NCBRESET return code is: 0x%x \n"), bRetCode );
     
        memset( &ncb, 0, sizeof(ncb) );
        ncb.ncb_command = NCBASTAT;
        ncb.ncb_lana_num = 0;
     
        // Must be in non-unicode
        strcpy( (char*) ncb.ncb_callname,  "*               " );
        ncb.ncb_buffer = (unsigned char *) &Adapter;
        ncb.ncb_length = sizeof(Adapter);
     
        bRetCode = Netbios( &ncb );
        _tprintf( _T("The NCBASTAT return code is: 0x%x \n"), bRetCode );
        if ( bRetCode == 0 )
        {
            _tprintf( _T("The MAC Address is: %02x%02x%02x%02x%02x%02x\n"),
                    Adapter.adapt.adapter_address[0],
                    Adapter.adapt.adapter_address[1],
                    Adapter.adapt.adapter_address[2],
                    Adapter.adapt.adapter_address[3],
                    Adapter.adapt.adapter_address[4],
                    Adapter.adapt.adapter_address[5] );
        }
        return 0;
    }
    Succinct is verbose for terse

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured