A good programmer is a person. See more think perhaps he mountain stone can attack jade, but never become the slave of code. Cker
Original: Borland
Translated by Cker
The first approach uses the Microsoft NetBIOS API. This is a set of commands that provide the underlying network support via Winsock. The biggest disadvantage of using NetBIOS is that you must have a NetBIOS service installed on your system (this is not a problem if you have file sharing enabled on the Windows network). Besides this, this method is quick and accurate.
The NetBIOS API includes only one function, called NetBIOS. This function uses the network control block (network) structure as a parameter, and this structure tells the function what to do. The structure is defined as follows:
typedef struct _NCB {
UCHAR ncb_command;
UCHAR ncb_retcode;
UCHAR ncb_lsn;
UCHAR ncb_num;
PUCHAR ncb_buffer;
WORD ncb_length;
UCHAR ncb_callname[NCBNAMSZ];
UCHAR ncb_name[NCBNAMSZ];
UCHAR ncb_rto;
UCHAR ncb_sto;
void (CALLBACK *ncb_post) (struct _NCB *);
UCHAR ncb_lana_num;
UCHAR ncb_cmd_cplt;
#ifdef _WIN64
UCHAR ncb_reserve[18];
#else
UCHAR ncb_reserve[10];
#endif
HANDLE ncb_event;
} NCB, *PNCB;
The focus is on Ncb_command members. The member told the NetBIOS what to do. We use three commands to detect the MAC address. Their definition of MSDN is as follows:
Command Description:
Ncbenum Windows nt/2000: Enumerates the number of network cards in the system. When this command is used, the Ncb_buffer member points to a buffer that is populated by the lana_enum structure.
Ncbenum is not a standard NetBIOS 3.0 command.
Ncbreset reset the network card. The NIC must be reset before accepting the new NCB command.
Ncbastat accept the status of the local or remote interface card. When this command is used, the Ncb_buffer member points to a buffer populated by the adapter_status structure followed by an array of name_buffer structures.
Here are the steps to get your system MAC address:
1 lists all the interface cards.
2 resets each card to obtain its correct information.
3 Query interface card, get MAC address and generate standard colon delimited format.