Skip to main content
Email Password   helpLost your password?

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;
}
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralNetBios Return ErrorCode 23 (Data error (cyclic redundancy check). ) Pin
Member 3761148
1:59 29 Jul '09  
GeneralNetBios API not working for Windows Vista Pin
Ankush123
21:43 12 Feb '09  
GeneralBIOS Name Pin
SalvaThor23
20:20 29 Nov '07  
GeneralWon't work ? Pin
excepter2k
2:20 25 Sep '05  
GeneralRe: Won't work ? Pin
joe_chen1
18:24 14 Jun '07  
GeneralGet MAC Address Pin
Jagmal
20:30 1 Feb '05  
GeneraliWhat i pass to sNetBiosName Pin
equebal
4:34 24 Dec '04  
GeneralRe: iWhat i pass to sNetBiosName Pin
joe_chen1
18:25 14 Jun '07  
GeneralWhat do I pass in? Pin
pjobson
6:27 2 Aug '04  
GeneralNeed Get mac address on Foxpro 2.6 under Ms-dos Pin
morteza_mousavi
2:01 9 Jul '04  
GeneralNeed Get MAC Address Source Code and ActiveX Control or DLL Library for VB,VFP Pin
John Nu
20:11 23 Mar '04  
Generaldetect my NIC device is connected to the LAN Pin
tangming0520
21:04 5 Feb '04  
GeneralIf not connected Pin
gcolsani
12:00 7 Oct '03  
Generalthis example juste come from... Pin
scoubidou944@hotmail.com
6:39 21 Aug '03  
GeneralRe: this example juste come from... Pin
Ryszard Krakowiak
3:28 26 Aug '03  
Generalwhy I can't pass link? Pin
Shinypro
22:17 8 Dec '02  
GeneralRe: why I can't pass link? Pin
Ryszard Krakowiak
22:26 12 Dec '02  
GeneralProtocol independent way of getting MAC Pin
Goran Car
10:39 30 Aug '02  
GeneralRe: Protocol independent way of getting MAC Pin
eta
11:37 10 Sep '03  
GeneralRe: Protocol independent way of getting MAC Pin
zero.sg
21:14 5 Feb '04  
GeneralRe: Protocol independent way of getting MAC Pin
funvill
12:34 7 Jul '06  
GeneralMAC from multiple sources. Pin
Peter Donahue
10:51 14 May '02  
GeneralVery very good job. Pin
VCPP6
20:25 15 Nov '04  
GeneralRe: MAC from multiple sources. Pin
sizheng
0:30 7 Jul '05  
GeneralRe: MAC from multiple sources. Pin
Peter Donahue
4:40 11 May '06  


Last Updated 11 May 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009