再见了,单纯拼凑 2022-04-07 00:04 采纳率: 0%
浏览 29

Python 获取移动硬盘盒里的硬盘信息

如果移动硬盘是固态硬盘,那么多如何读取它的fw sn等信息呢?

  • 写回答

1条回答 默认 最新

  • 北京生信课堂 2022-04-07 09:06
    关注

    亲亲,尝试下面的代码,需要安装import里的依赖

    import sys, os, fcntl, struct
    if os.geteuid() >  0:
        print("ERROR: Must be root to use")
        sys.exit(1)
    with open(sys.argv[1], "rb") as fd:
        # tediously derived from the monster struct defined in <hdreg.h>
        # see comment at end of file to verify
        hd_driveid_format_str = "@ 10H 20s 3H 8s 40s 2B H 2B H 4B 6H 2B I 36H I Q 152H"
        # Also from <hdreg.h>
        HDIO_GET_IDENTITY = 0x030d
        # How big a buffer do we need?
        sizeof_hd_driveid = struct.calcsize(hd_driveid_format_str)
    
        # ensure our format string is the correct size
        # 512 is extracted using sizeof(struct hd_id) in the c code
        assert sizeof_hd_driveid == 512 
    
        # Call native function
        buf = fcntl.ioctl(fd, HDIO_GET_IDENTITY, " " * sizeof_hd_driveid)
        fields = struct.unpack(hd_driveid_format_str, buf)
        serial_no = fields[10].strip()
        model = fields[15].strip()
        print("FW为l: %s" % model)
        print("  SN序列号为: %s" % serial_no)
    
    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 4月7日

悬赏问题

  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏