Click here to Skip to main content
6,292,426 members and growing! (10,035 online)
Email Password   helpLost your password?
General Programming » Internet / Network » General     Intermediate

Get MAC Address

By Ryszard Krakowiak

Get MAC address function
VC6Win2K, Visual Studio, MFC, Dev
Posted:6 Aug 2001
Updated:11 May 2002
Views:175,754
Bookmarked:29 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
28 votes for this article.
Popularity: 3.31 Rating: 2.29 out of 5
4 votes, 66.7%
1

2

3
1 vote, 16.7%
4
1 vote, 16.7%
5

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


Member

Occupation: Web Developer
Location: Poland Poland

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 49 (Total in Forum: 49) (Refresh)FirstPrevNext
GeneralNetBios API not working for Windows Vista PinmemberAnkush12321:43 12 Feb '09  
GeneralBIOS Name PinmemberSalvaThor2320:20 29 Nov '07  
GeneralWon't work ? Pinsussexcepter2k2:20 25 Sep '05  
GeneralRe: 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  
GeneralWhat 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  
GeneralRe: this example juste come from... PinmemberRyszard Krakowiak3:28 26 Aug '03  
Generalwhy I can't pass link? PinmemberShinypro22:17 8 Dec '02  
GeneralRe: 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  
GeneralRe: MAC from multiple sources. PinmemberPeter Donahue4:40 11 May '06  
GeneralRe: MAC from multiple sources. PinmemberJasonShen11118:29 10 May '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 May 2002
Editor: Brian Delahunty
Copyright 2001 by Ryszard Krakowiak
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project