Click here to Skip to main content
Licence 
First Posted 6 Aug 2001
Views 218,257
Bookmarked 35 times

Get MAC Address

By | 11 May 2002 | Article
Get MAC address function

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

About the Author

Ryszard Krakowiak

Web Developer

Poland Poland

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthis worked for me !! Pinmemberapp_devlpr18:49 21 Mar '10  
GeneralNetBios Return ErrorCode 23 (Data error (cyclic redundancy check). ) PinmemberMember 37611480:59 29 Jul '09  
GeneralNetBios API not working for Windows Vista PinmemberAnkush12320:43 12 Feb '09  
GeneralBIOS Name PinmemberSalvaThor2319:20 29 Nov '07  
QuestionWon't work ? Pinsussexcepter2k1:20 25 Sep '05  
AnswerRe: Won't work ? Pinmemberjoe_chen117:24 14 Jun '07  
GeneralGet MAC Address PinmemberJagmal19:30 1 Feb '05  
GeneraliWhat i pass to sNetBiosName Pinmemberequebal3:34 24 Dec '04  
What I Pass to sNetBiosName when calling GetMacAddress function.
 
equebal
GeneralRe: iWhat i pass to sNetBiosName Pinmemberjoe_chen117:25 14 Jun '07  
QuestionWhat do I pass in? Pinmemberpjobson5:27 2 Aug '04  
GeneralNeed Get mac address on Foxpro 2.6 under Ms-dos Pinsussmorteza_mousavi1:01 9 Jul '04  
GeneralNeed Get MAC Address Source Code and ActiveX Control or DLL Library for VB,VFP PinsussJohn Nu19:11 23 Mar '04  
Generaldetect my NIC device is connected to the LAN Pinmembertangming052020:04 5 Feb '04  
GeneralIf not connected Pinmembergcolsani11:00 7 Oct '03  
Generalthis example juste come from... Pinmemberscoubidou944@hotmail.com5:39 21 Aug '03  
GeneralRe: this example juste come from... PinmemberRyszard Krakowiak2:28 26 Aug '03  
Questionwhy I can't pass link? PinmemberShinypro21:17 8 Dec '02  
AnswerRe: why I can't pass link? PinmemberRyszard Krakowiak21:26 12 Dec '02  
GeneralProtocol independent way of getting MAC PinmemberGoran Car9:39 30 Aug '02  
GeneralRe: Protocol independent way of getting MAC Pinmembereta10:37 10 Sep '03  
GeneralRe: Protocol independent way of getting MAC Pinmemberzero.sg20:14 5 Feb '04  
GeneralRe: Protocol independent way of getting MAC Pinmemberfunvill11:34 7 Jul '06  
GeneralMAC from multiple sources. PinmemberPeter Donahue9:51 14 May '02  
GeneralVery very good job. PinmemberVCPP619:25 15 Nov '04  
GeneralRe: MAC from multiple sources. Pinmembersizheng23:30 6 Jul '05  

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.

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