在Linux下用c编程怎么获取网卡序列号和硬盘序列号?

hxliurui 2003-11-21 11:11:51
在Linux下用c编程怎么获取网卡序列号和硬盘序列号?
...全文
422 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tear_pearl 2003-12-10
  • 打赏
  • 举报
回复
只能非常抱歉了,我没有弄过而且也没环境
hxliurui 2003-12-08
  • 打赏
  • 举报
回复
[root@xxxxxxxx]# cat scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ADAPTEC Model: RAID-1 Rev: 380E
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 06 Lun: 00
Vendor: ESG-SHV Model: SCA HSBP M16 Rev: 0.05
Type: Processor

我得到是这样的,上面一个是阵列卡,下面一个 是什么
我 的scsi目录下没有sg子目录
hxliurui 2003-12-07
  • 打赏
  • 举报
回复
能够知道机器识别码更好,solaries下有个sysinfo可以读一个唯一的机器识别码,linux下有类似的函数吗?(linux下的sysinfo读不出这个值)
主板号也行
CPU号也行
实在不行只有弄SCSI了,可是scsi接口还有很多其它设备。。。
iyuchen 2003-12-07
  • 打赏
  • 举报
回复
关注
hxliurui 2003-12-07
  • 打赏
  • 举报
回复
up
tear_pearl 2003-12-07
  • 打赏
  • 举报
回复
读/proc/scsi应该可以
给你个网址
http://www.linux.org/docs/ldp/howto/SCSI-Generic-HOWTO/proc.html
不知道你所说的序列号是不是他所说的id
如果是的话那就可以读/proc/scsi/sg/debug得到它
hxliurui 2003-12-06
  • 打赏
  • 举报
回复
网卡有了:
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#include <arpa/inet.h>
#include "SysInfo.h"

#define MAXINTERFACES 16

int GetNicSerialNumber(char *szSerial, int length)
{
register int fd, intrface, retn = 0;
struct ifreq buf[MAXINTERFACES];
struct arpreq arp;
struct ifconf ifc;

if(length <= 12)
return -1;



if ((fd = socket (AF_INET, SOCK_DGRAM, 0)) >= 0)
{
ifc.ifc_len = sizeof buf;
ifc.ifc_buf = (caddr_t) buf;
if (!ioctl (fd, SIOCGIFCONF, (char *) &ifc))
{
intrface = ifc.ifc_len / sizeof (struct ifreq);
if (intrface > 1)
{
fprintf(stderr, "There are %d lan adapters in the system, only the first validate one is used\n", intrface);
intrface = 1;
}
if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[intrface])))
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[0],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[1],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[2],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[3],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[4],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[5]);

puts("");
puts("");
sprintf((char *)szSerial, "%02X%02X%02X%02X%02X%02X",(unsigned char)buf[intrface].ifr_hwaddr.sa_data[0],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[1],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[2],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[3],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[4],
(unsigned char)buf[intrface].ifr_hwaddr.sa_data[5]);


}
else
{
fprintf(stderr, "Get lana state failure\n");
}


}
else
{
fprintf(stderr, "Get lana state failure\n");
}


}
else
{
fprintf(stderr, "Socket error!\n" );
}
return 0;
#endif
}


硬盘没办法,只有用hdparm -iv /dev/hda读
但是这个命令只能读IDE硬盘,SCSI硬盘的参数(含序列号)用什么命令读啊??????????
hero1840 2003-12-05
  • 打赏
  • 举报
回复
up
hxliurui 2003-12-05
  • 打赏
  • 举报
回复
或者机器、主板、CPU任一都 行??????????????
liuty2006 2003-11-26
  • 打赏
  • 举报
回复
up
hxliurui 2003-11-23
  • 打赏
  • 举报
回复
help

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧