Article ID: 118623 - View products that this article applies to.
This article was previously published under Q118623
This article demonstrates how to get the Media Access Control (MAC) address for an ethernet adapter programmatically by using NetBIOS, if your card is bound to NetBIOS.
To get the Media Access Control (MAC) address for an ethernet adapter programmatically, use the Netbios() NCBASTAT command and provide a "*" as the name in the NCB.ncb_CallName field. This is demonstrated in the sample code below.
For computers with multiple network adapters you need to enumerate the LANA numbers and perform the NCBASTAT command on each. Even when you have a single network adapter, it is a good idea to enumerate valid LANA numbers first and perform the NCBASTAT on one of the valid LANA numbers. It is considered bad programming to hardcode the LANA number to 0.
In addition, other hardware and software may be assigned their own MAC addresses. For example, a modem can have a MAC address. Also, a RAS client or server can install "dummy" network adapters that correspond to a dialup or serial connection. Normally, these MAC addresses are randomly generated. If an adapter status is called on a LANA that corresponds to one of these adapters when no connection is present, Netbios returns error 0x34 (NRC_ENVNOTDEF) even if a reset was previously performed.
With the NetBEUI and IPX transports, the same information can be obtained at a command prompt by using:
The ID given is the MAC address.
net config workstation
The following code enumerates all LANA numbers, performs a reset (NCBREST), and an adapter status (NCBASTAT).
Article ID: 118623 - Last Review: July 8, 2005 - Revision: 2.5
Contact us for more help
Connect with Answer Desk for expert help.