免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2706 | 回复: 3
打印 上一主题 下一主题

哪里有检测网卡ID号的程序?在unix 下? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-06-28 00:05 |只看该作者 |倒序浏览
我希望做用网卡id号为key的加密。哪位大侠不吝赐告?

论坛徽章:
0
2 [报告]
发表于 2003-06-28 10:14 |只看该作者

哪里有检测网卡ID号的程序?在unix 下?

这个问题很难呀!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2003-06-29 10:16 |只看该作者

哪里有检测网卡ID号的程序?在unix 下?


  1. #include <stdio.h>;
  2. #include <sys/types.h>;
  3. #include <sys/param.h>;

  4. #include <sys/ioctl.h>;
  5. #include <sys/socket.h>;
  6. #include <net/if.h>;
  7. #include <netinet/in.h>;
  8. #include <net/if_arp.h>;

  9. #define MAXINTERFACES   16

  10. main (argc, argv)
  11. register int argc;
  12. register char *argv[];
  13. {
  14.    register int fd, intrface, retn = 0;
  15.    struct ifreq buf[MAXINTERFACES];
  16.    struct arpreq arp;
  17.    struct ifconf ifc;

  18.    if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >;= 0) {
  19.       ifc.ifc_len = sizeof buf;
  20.       ifc.ifc_buf = (caddr_t) buf;
  21.       if (!ioctl (fd, SIOCGIFCONF, (char *) &ifc)) {
  22.          intrface = ifc.ifc_len / sizeof (struct ifreq);
  23.          printf("interface num is intrface=%d\n\n\n",intrface);
  24.          while (intrface-- >; 0)
  25.           {
  26.             printf ("net device %s\n", buf[intrface].ifr_name);

  27. /*Jugde whether the net card status is promisc  */
  28.             if (!(ioctl (fd, SIOCGIFFLAGS, (char *) &buf[intrface]))) {
  29.                if (buf[intrface].ifr_flags & IFF_PROMISC) {
  30.                   puts ("the interface is PROMISC");
  31.                   retn++;
  32.                }
  33.             } else {
  34.                char str[256];

  35.                sprintf (str, "cpm: ioctl device %s", buf[intrface].ifr_name);
  36.                perror (str);
  37.             }

  38. /*Jugde whether the net card status is up       */
  39.             if (buf[intrface].ifr_flags & IFF_UP) {
  40.                 puts("the interface status is UP");
  41.                }
  42.             else {
  43.                 puts("the interface status is DOWN");
  44.             }

  45. /*Get IP of the net card */
  46.             if (!(ioctl (fd, SIOCGIFADDR, (char *) &buf[intrface])))
  47.                 {
  48.                  puts ("IP address is:");
  49.                  puts(inet_ntoa(((struct sockaddr_in*)(&buf[intrface].ifr_addr))->;sin_addr));
  50.                  puts("");
  51.                    //puts (buf[intrface].ifr_addr.sa_data);
  52.                 }
  53.             else {
  54.                char str[256];

  55.                sprintf (str, "cpm: ioctl device %s", buf[intrface].ifr_name);
  56.                perror (str);
  57.            }
  58. /* this section can't get Hardware Address,I don't know whether the reason is module driver
  59. //          ((struct sockaddr_in*)&arp.arp_pa)->;sin_addr=((struct sockaddr_in*)(&buf[intrface].ifr_addr))->;sin_addr;
  60.             arp.arp_pa.sa_family = AF_INET;
  61.             arp.arp_ha.sa_family = AF_INET;
  62.             ((struct sockaddr_in*)&arp.arp_pa)->;sin_addr.s_addr=((struct sockaddr_in*)(&buf[intrface].ifr_addr))->;sin_addr.s_addr;
  63.             if (!(ioctl (fd, SIOCGARP, (char *) &arp)))
  64.                 {
  65.                  puts ("HW address is:");

  66.                  printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
  67.                                 (unsigned char)arp.arp_ha.sa_data[0],
  68.                                 (unsigned char)arp.arp_ha.sa_data[1],
  69.                                 (unsigned char)arp.arp_ha.sa_data[2],
  70.                                 (unsigned char)arp.arp_ha.sa_data[3],
  71.                                 (unsigned char)arp.arp_ha.sa_data[4],
  72.                                 (unsigned char)arp.arp_ha.sa_data[5]);

  73.                  puts("");
  74.                  puts("");
  75.                 }

  76. */

  77. /*Get HW ADDRESS of the net card */
  78.             if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[intrface])))
  79.                 {
  80.                  puts ("HW address is:");

  81.                  printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
  82.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[0],
  83.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[1],
  84.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[2],
  85.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[3],
  86.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[4],
  87.                                 (unsigned char)buf[intrface].ifr_hwaddr.sa_data[5]);

  88.                  puts("");
  89.                  puts("");
  90.                 }

  91.             else {
  92.                char str[256];

  93.                sprintf (str, "cpm: ioctl device %s", buf[intrface].ifr_name);
  94.                perror (str);
  95.            }
  96.         }
  97.       } else
  98.          perror ("cpm: ioctl");

  99.    } else
  100.       perror ("cpm: socket");

  101.     close (fd);
  102.     return retn;
  103. }
复制代码

论坛徽章:
0
4 [报告]
发表于 2004-02-11 18:00 |只看该作者

哪里有检测网卡ID号的程序?在unix 下?

为什么在Sco unix下运行该程序,宏ioctl(sockfd,SIOCGARP,&arp)报错
No such device and address
我在Sco unix 下,man ioctl_list 没有这个东东!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP