Click here to Skip to main content
12,349,884 members (21,749 online)
Click here to Skip to main content
Add your own
alternative version

Stats

251.3K views
36 bookmarked
Posted

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

You may also be interested in...

Comments and Discussions

 
Generalthis worked for me !! Pin
app_devlpr21-Mar-10 18:49
memberapp_devlpr21-Mar-10 18:49 
GeneralNetBios Return ErrorCode 23 (Data error (cyclic redundancy check). ) Pin
Member 376114829-Jul-09 0:59
memberMember 376114829-Jul-09 0:59 
GeneralNetBios API not working for Windows Vista Pin
Ankush12312-Feb-09 20:43
memberAnkush12312-Feb-09 20:43 
GeneralBIOS Name Pin
SalvaThor2329-Nov-07 19:20
memberSalvaThor2329-Nov-07 19:20 
QuestionWon't work ? Pin
excepter2k25-Sep-05 1:20
sussexcepter2k25-Sep-05 1:20 
AnswerRe: Won't work ? Pin
joe_chen114-Jun-07 17:24
memberjoe_chen114-Jun-07 17:24 
GeneralGet MAC Address Pin
Jagmal1-Feb-05 19:30
memberJagmal1-Feb-05 19:30 
GeneraliWhat i pass to sNetBiosName Pin
equebal24-Dec-04 3:34
memberequebal24-Dec-04 3:34 
GeneralRe: iWhat i pass to sNetBiosName Pin
joe_chen114-Jun-07 17:25
memberjoe_chen114-Jun-07 17:25 
QuestionWhat do I pass in? Pin
pjobson2-Aug-04 5:27
memberpjobson2-Aug-04 5:27 
GeneralNeed Get mac address on Foxpro 2.6 under Ms-dos Pin
morteza_mousavi9-Jul-04 1:01
sussmorteza_mousavi9-Jul-04 1:01 
GeneralNeed Get MAC Address Source Code and ActiveX Control or DLL Library for VB,VFP Pin
John Nu23-Mar-04 19:11
sussJohn Nu23-Mar-04 19:11 
Generaldetect my NIC device is connected to the LAN Pin
tangming05205-Feb-04 20:04
membertangming05205-Feb-04 20:04 
GeneralIf not connected Pin
gcolsani7-Oct-03 11:00
membergcolsani7-Oct-03 11:00 
Generalthis example juste come from... Pin
scoubidou944@hotmail.com21-Aug-03 5:39
memberscoubidou944@hotmail.com21-Aug-03 5:39 
GeneralRe: this example juste come from... Pin
Ryszard Krakowiak26-Aug-03 2:28
memberRyszard Krakowiak26-Aug-03 2:28 
Questionwhy I can't pass link? Pin
Shinypro8-Dec-02 21:17
memberShinypro8-Dec-02 21:17 
AnswerRe: why I can't pass link? Pin
Ryszard Krakowiak12-Dec-02 21:26
memberRyszard Krakowiak12-Dec-02 21:26 
GeneralProtocol independent way of getting MAC Pin
Goran Car30-Aug-02 9:39
memberGoran Car30-Aug-02 9:39 
GeneralRe: Protocol independent way of getting MAC Pin
eta10-Sep-03 10:37
membereta10-Sep-03 10:37 
GeneralRe: Protocol independent way of getting MAC Pin
zero.sg5-Feb-04 20:14
memberzero.sg5-Feb-04 20:14 
GeneralRe: Protocol independent way of getting MAC Pin
funvill7-Jul-06 11:34
memberfunvill7-Jul-06 11:34 
GeneralMAC from multiple sources. Pin
Peter Donahue14-May-02 9:51
memberPeter Donahue14-May-02 9:51 
GeneralVery very good job. Pin
VCPP615-Nov-04 19:25
memberVCPP615-Nov-04 19:25 
GeneralRe: MAC from multiple sources. Pin
sizheng6-Jul-05 23:30
membersizheng6-Jul-05 23:30 
GeneralRe: MAC from multiple sources. Pin
Peter Donahue11-May-06 3:40
memberPeter Donahue11-May-06 3:40 
GeneralRe: MAC from multiple sources. Pin
JasonShen11110-May-06 17:29
memberJasonShen11110-May-06 17:29 
GeneralRe: MAC from multiple sources. Pin
Peter Donahue11-May-06 3:43
memberPeter Donahue11-May-06 3:43 
GeneralRe: MAC from multiple sources. Pin
Peter Donahue11-May-06 3:46
memberPeter Donahue11-May-06 3:46 
GeneralRe: MAC from multiple sources. Pin
Claude5-Dec-07 21:48
sussClaude5-Dec-07 21:48 
GeneralAnother method Pin
Mike C5-Mar-02 3:43
memberMike C5-Mar-02 3:43 
GeneralRe: Another method Pin
bluesky13730-Mar-03 21:04
memberbluesky13730-Mar-03 21:04 
QuestionWhat's wrong with using ARP request? Pin
Goran Car21-Oct-01 12:06
memberGoran Car21-Oct-01 12:06 
AnswerRe: What's wrong with using ARP request? Pin
Lindia7-Jul-02 6:18
memberLindia7-Jul-02 6:18 
AnswerRe: What's wrong with using ARP request? Pin
Lindia7-Jul-02 6:18
memberLindia7-Jul-02 6:18 
GeneralThis is a MSDN sample... Pin
Anonymous12-Aug-01 23:17
memberAnonymous12-Aug-01 23:17 
GeneralRe: This is a MSDN sample... Pin
Msftone17-Nov-02 14:21
memberMsftone17-Nov-02 14:21 
QuestionWhat about multiple NICs? Pin
Igor Proskuriakov8-Aug-01 8:13
memberIgor Proskuriakov8-Aug-01 8:13 
AnswerRe: What about multiple NICs? Pin
Ryszard Krakowiak8-Aug-01 19:48
memberRyszard Krakowiak8-Aug-01 19:48 
AnswerRe: What about multiple NICs? Pin
DavidCrow16-Jun-05 4:02
memberDavidCrow16-Jun-05 4:02 
QuestionDoes this require NetBios to be installed? Pin
njc7-Aug-01 3:51
membernjc7-Aug-01 3:51 
AnswerRe: Does this require NetBios to be installed? Pin
Loren Rogers9-Aug-01 10:06
memberLoren Rogers9-Aug-01 10:06 
GeneralThis should not be allowed as a submission Pin
John Smith7-Aug-01 2:50
memberJohn Smith7-Aug-01 2:50 
GeneralRe: This should not be allowed as a submission Pin
Serge Weinstock7-Aug-01 3:40
memberSerge Weinstock7-Aug-01 3:40 
GeneralRe: This should not be allowed as a submission Pin
John Simmons / outlaw programmer7-Aug-01 6:21
memberJohn Simmons / outlaw programmer7-Aug-01 6:21 
GeneralRe: This should not be allowed as a submission Pin
Marc Richarme17-Aug-01 1:48
memberMarc Richarme17-Aug-01 1:48 
GeneralRe: This should not be allowed as a submission Pin
MyMojo1-Apr-03 1:58
memberMyMojo1-Apr-03 1:58 
GeneralRe: This should not be allowed as a submission Pin
Anonymous7-Aug-01 9:09
memberAnonymous7-Aug-01 9:09 
GeneralRe: This should not be allowed as a submission Pin
Anonymous8-Aug-01 12:21
memberAnonymous8-Aug-01 12:21 
GeneralRe: This should not be allowed as a submission Pin
MyMojo1-Apr-03 2:04
memberMyMojo1-Apr-03 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160621.1 | Last Updated 12 May 2002
Article Copyright 2001 by Ryszard Krakowiak
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid