#macchanger -s eth0可以获得mac的真实mac地址 Current MAC: 00:07:3e:90:45:92 (China Great-Wall Computer Shenzhen Co., Ltd.) Permanent MAC: 00:07:3e:90:45:7f (China Great-Wall Computer Shenzhen Co., Ltd.)
1 #include "maclist.h" 2 #include "netinfo.h" //ljc 18/11/21 查看mac地址的原始值和临时值 3 int Get_CP_Mac(char *device_name, char *Current_Mac, char *Permanent_Mac) 4 { 5 if((device_name == NULL) || (Current_Mac == NULL) || (Permanent_Mac == NULL)) 6 { 7 printf("*Get_CP_Mac start init failed!!!! "); return EXIT_ERROR; 8 } 9 net_info_t *net; 10 mac_t *mac; 11 mac_t *mac_permanent; /* Read the MAC lists */ 12 if (mc_maclist_init() < 0) 13 { printf("*MAC lists init failed!!!!"); return EXIT_ERROR; } 14 printf("*device_name :%s ",device_name); 15 if ((net = mc_net_info_new(device_name)) == NULL) 16 { printf("*mc_net_info failed!!!!"); return EXIT_ERROR; } 17 printf("*+++++++++malloc++++ net %p ",net); 18 mac = mc_net_info_get_mac(net); 19 printf("*+++++++++malloc++++ mac %p ",mac); 20 mac_permanent = mc_net_info_get_permanent_mac(net); 21 printf("*+++++++++malloc++++ mac_permanent %p ",mac_permanent); //获得临时mac地址
int is_wireless;
is_wireless = mc_maclist_is_wireless(mac); 22 mc_mac_into_string (mac, Current_Mac); //获得永久mac地址 23 is_wireless = mc_maclist_is_wireless(mac_permanent); 24 mc_mac_into_string (mac_permanent, Permanent_Mac); 25 printf("temp——mac:%s ", Current_Mac); 26 printf("Permanent——mac:%s ", Permanent_Mac); 27 printf(" *1---free--- net %p ",net); 28 mc_net_info_free (net); 29 printf("*2---free--- mac %p ",mac); 30 mc_mac_free (mac); 31 printf("*3---free--- mac_permanent %p ",mac_permanent); 32 mc_mac_free (mac_permanent); 33 mc_maclist_free(); 34 return EXIT_OK; 35 } //ljc 18/11/21 36 37 //(test code) 38 char Current_Mac[MAC_LEN]; 39 char Permanent_Mac[MAC_LEN]; 40 int Ret = Get_CP_Mac(mac_Info_name,Current_Mac, Permanent_Mac); 41 if(Ret == EXIT_ERROR) 42 { return -1; } 43 printf("temp——mac:%s ", Current_Mac); 44 printf("Permanent——mac:%s ", Permanent_Mac);