Get the system network card MAC address method

xiaoxiao2021-03-06  75

This method uses the COM API to create a GUID (globally unique identifier) ​​and inherit the MAC address there. GUID is usually used to identify COM components and other objects in the system. They are calculated from the MAC address (combined with other things), and the MAC address on the surface is included there. I said that the surface is because it doesn't contain it. I provide this approach to more than a brock. You may use this method to get the MAC address, but sometimes you only get a random hexadecimal value. The following example is very simple, there is no need to talk more. We use CocreateGuid to create a GUID and place the last six bytes in a string. They may be a MAC address, but it is not necessarily.

UUID.cpp #include #include #include

Using namespace std;

INT main () {cout << "Mac Address IS:";

/ / A UUID to COM. If there is an Ethernet card in the machine, // uuid's last six bytes (2-7 bytes of DATA4) should be the MAC address of the local Ethernet card. Guid uuid; cocreateguid; // spit the address out char mac_addr [18]; sprintf (mac_addr, "% 02x:% 02x:% 02x:% 02x:% 02x:% 02x", uuid.data4 [2] UUID.DATA4 [3], uuid.data4 [4], uuid.data4 [5], uuid.data4 [6], uuid.data4 [7]); cout << mac_addr << Endl; getch (); return }

转载请注明原文地址:https://www.9cbs.com/read-93762.html

New Post(0)