Click here to Skip to main content
Licence 
First Posted 6 Aug 2001
Views 214,058
Bookmarked 34 times

Get MAC Address

By Ryszard Krakowiak | 11 May 2002
Get MAC address function
4 votes, 66.7%
1

2

3
1 vote, 16.7%
4
1 vote, 16.7%
5
2.29/5 - 28 votes
μ 2.29, σa 3.21 [?]

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_devlpr19:49 21 Mar '10  
GeneralNetBios Return ErrorCode 23 (Data error (cyclic redundancy check). ) PinmemberMember 37611481:59 29 Jul '09  
GeneralNetBios API not working for Windows Vista PinmemberAnkush12321:43 12 Feb '09  
GeneralBIOS Name PinmemberSalvaThor2320:20 29 Nov '07  
QuestionWon't work ? Pinsussexcepter2k2:20 25 Sep '05  
AnswerRe: Won't work ? Pinmemberjoe_chen118:24 14 Jun '07  
GeneralGet MAC Address PinmemberJagmal20:30 1 Feb '05  
GeneraliWhat i pass to sNetBiosName Pinmemberequebal4:34 24 Dec '04  
GeneralRe: iWhat i pass to sNetBiosName Pinmemberjoe_chen118:25 14 Jun '07  
QuestionWhat do I pass in? Pinmemberpjobson6:27 2 Aug '04  
GeneralNeed Get mac address on Foxpro 2.6 under Ms-dos Pinsussmorteza_mousavi2:01 9 Jul '04  
GeneralNeed Get MAC Address Source Code and ActiveX Control or DLL Library for VB,VFP PinsussJohn Nu20:11 23 Mar '04  
Generaldetect my NIC device is connected to the LAN Pinmembertangming052021:04 5 Feb '04  
GeneralIf not connected Pinmembergcolsani12:00 7 Oct '03  
Generalthis example juste come from... Pinmemberscoubidou944@hotmail.com6:39 21 Aug '03  
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q118/6/23.asp&NoWebContent=1
 
and here, compile will works
GeneralRe: this example juste come from... PinmemberRyszard Krakowiak3:28 26 Aug '03  
Questionwhy I can't pass link? PinmemberShinypro22:17 8 Dec '02  
AnswerRe: why I can't pass link? PinmemberRyszard Krakowiak22:26 12 Dec '02  
GeneralProtocol independent way of getting MAC PinmemberGoran Car10:39 30 Aug '02  
GeneralRe: Protocol independent way of getting MAC Pinmembereta11:37 10 Sep '03  
GeneralRe: Protocol independent way of getting MAC Pinmemberzero.sg21:14 5 Feb '04  
GeneralRe: Protocol independent way of getting MAC Pinmemberfunvill12:34 7 Jul '06  
GeneralMAC from multiple sources. PinmemberPeter Donahue10:51 14 May '02  
GeneralVery very good job. PinmemberVCPP620:25 15 Nov '04  
GeneralRe: MAC from multiple sources. Pinmembersizheng0:30 7 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.120210.1 | Last Updated 12 May 2002
Article Copyright 2001 by Ryszard Krakowiak
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid