• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
金色洋光
学习是最好的投资
博客园    首页    新随笔    联系   管理     

Macchanger-查看Linux的当前临时有效的mac地址和永久物理的mac地址

#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!!!!\n"); 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\n\n",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\n",net); 
18     mac = mc_net_info_get_mac(net); 
19     printf("*+++++++++malloc++++ mac %p\n",mac); 
20     mac_permanent = mc_net_info_get_permanent_mac(net); 
21     printf("*+++++++++malloc++++ mac_permanent %p\n",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\n", Current_Mac); 26 printf("Permanent——mac:%s\n", Permanent_Mac); 27 printf("\n*1---free--- net %p\n",net); 28 mc_net_info_free (net); 29 printf("*2---free--- mac %p\n",mac); 30 mc_mac_free (mac); 31 printf("*3---free--- mac_permanent %p\n\n",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\n", Current_Mac); 44 printf("Permanent——mac:%s\n", Permanent_Mac);

 

每一成功的背后都有个人的努力和家人的支持
posted @ 2018-12-28 17:31  金色洋光  阅读(785)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3