Three ways to get the MAC address of the NIC in the system

Source: Internet
Author: User
Tags reset

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.