#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.)
#include "maclist.h"
#include "netinfo.h"
//ljc 18/11/21 查看mac地址的原始值和临时值
int Get_CP_Mac(char *device_name, char *Current_Mac, char *Permanent_Mac)
{
if((device_name == NULL) || (Current_Mac == NULL) || (Permanent_Mac == NULL))
{
printf("*Get_CP_Mac start init failed!!!!\n");
return EXIT_ERROR;
}
net_info_t *net;
mac_t *mac;
mac_t *mac_permanent;
/* Read the MAC lists */
if (mc_maclist_init() < 0)
{
printf("*MAC lists init failed!!!!");
return EXIT_ERROR;
}
printf("*device_name :%s\n\n",device_name);
if ((net = mc_net_info_new(device_name)) == NULL)
{
printf("*mc_net_info failed!!!!");
return EXIT_ERROR;
}
printf("*+++++++++malloc++++ net %p\n",net);
mac = mc_net_info_get_mac(net);
printf("*+++++++++malloc++++ mac %p\n",mac);
mac_permanent = mc_net_info_get_permanent_mac(net);
printf("*+++++++++malloc++++ mac_permanent %p\n",mac_permanent);
//获得临时mac地址
int is_wireless;
is_wireless = mc_maclist_is_wireless(mac);
mc_mac_into_string (mac, Current_Mac);
//获得永久mac地址
is_wireless = mc_maclist_is_wireless(mac_permanent);
mc_mac_into_string (mac_permanent, Permanent_Mac);
printf("temp——mac:%s\n", Current_Mac);
printf("Permanent——mac:%s\n", Permanent_Mac);
printf("\n*1---free--- net %p\n",net);
mc_net_info_free (net);
printf("*2---free--- mac %p\n",mac);
mc_mac_free (mac);
printf("*3---free--- mac_permanent %p\n\n",mac_permanent);
mc_mac_free (mac_permanent);
mc_maclist_free();
return EXIT_OK;
}
//ljc 18/11/21
char Current_Mac[MAC_LEN];
char Permanent_Mac[MAC_LEN];
int Ret = Get_CP_Mac(mac_Info_name,Current_Mac, Permanent_Mac);
if(Ret == EXIT_ERROR)
{
return -1;
}
printf("temp——mac:%s\n", Current_Mac);
printf("Permanent——mac:%s\n", Permanent_Mac);Macchanger-查看Linux的当前临时有效的mac地址和永久物理的mac地址
原文:https://www.cnblogs.com/Lijcyy/p/9994848.html