Click to See Complete Forum and Search --> : getting the MacId


C.Schlue
April 16th, 2003, 02:23 AM
can anyone of you give me a hint on how to read the MacId(s) of my network adpter(s)???

cup
April 17th, 2003, 01:50 AM
On what OS/Compiler? The following works on MSVC6


#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;
}