Click here to Skip to main content
Click here to Skip to main content

Get MAC Address

, 11 May 2002
Rate this:
Please Sign up or sign in to vote.
Get MAC address function
<!-- Add the rest of your HTML here -->

GetMacAddress

Include nb30.h and link with netapi32.lib. This article is based on Q118623.

Source

typedef struct _ASTAT_
{
	ADAPTER_STATUS adapt;
	NAME_BUFFER    NameBuff[30];
} ASTAT, * PASTAT;


CString GetMacAddress(CString sNetBiosName)
{
    ASTAT Adapter;
	
    NCB ncb;
    UCHAR uRetCode;
	
    memset(&ncb, 0, sizeof(ncb));
    ncb.ncb_command = NCBRESET;
    ncb.ncb_lana_num = 0;
	
    uRetCode = Netbios(&ncb);
	
    memset(&ncb, 0, sizeof(ncb));
    ncb.ncb_command = NCBASTAT;
    ncb.ncb_lana_num = 0;
	
    sNetBiosName.MakeUpper();
	
    FillMemory(ncb.ncb_callname, NCBNAMSZ - 1, 0x20);
	
    strcpy((char *)ncb.ncb_callname, (LPCTSTR) sNetBiosName);
	
    ncb.ncb_callname[sNetBiosName.GetLength()] = 0x20;
    ncb.ncb_callname[NCBNAMSZ] = 0x0;
	
    ncb.ncb_buffer = (unsigned char *) &Adapter;
    ncb.ncb_length = sizeof(Adapter);
	
    uRetCode = Netbios(&ncb);
    
    CString sMacAddress;
	
    if (uRetCode == 0)
    {
    	sMacAddress.Format(_T("%02x%02x%02x%02x%02x%02x"),
    	    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 sMacAddress;
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Ryszard Krakowiak
Web Developer
Poland Poland
No Biography provided

Comments and Discussions

 
Generalthis worked for me !! Pinmemberapp_devlpr21-Mar-10 19:49 
GeneralNetBios Return ErrorCode 23 (Data error (cyclic redundancy check). ) PinmemberMember 376114829-Jul-09 1:59 
GeneralNetBios API not working for Windows Vista PinmemberAnkush12312-Feb-09 21:43 
GeneralBIOS Name PinmemberSalvaThor2329-Nov-07 20:20 
QuestionWon't work ? Pinsussexcepter2k25-Sep-05 2:20 
AnswerRe: Won't work ? Pinmemberjoe_chen114-Jun-07 18:24 
GeneralGet MAC Address PinmemberJagmal1-Feb-05 20:30 
GeneraliWhat i pass to sNetBiosName Pinmemberequebal24-Dec-04 4:34 
GeneralRe: iWhat i pass to sNetBiosName Pinmemberjoe_chen114-Jun-07 18:25 
QuestionWhat do I pass in? Pinmemberpjobson2-Aug-04 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 12 May 2002
Article Copyright 2001 by Ryszard Krakowiak
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid