python硬盘api-如何使用Python获取硬盘序列号

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

# 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

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("Hard Disk Model: %s" % model)

print(" Serial Number: %s" % serial_no)

## For documentation purposes, this is the struct copied from

# struct hd_driveid {

# unsigned short config; /* lots of obsolete bit flags */

# unsigned short cyls; /* Obsolete, "physical" cyls */

# unsigned short reserved2; /* reserved (word 2) */

# unsigned short heads; /* Obsolete, "physical" heads */

# unsigned short track_bytes; /* unformatted bytes per track */

# unsigned short sector_bytes; /* unformatted bytes per sector */

# unsigned short sectors; /* Obsolete, "physical" sectors per track */

# unsigned short vendor0; /* vendor unique */

# unsigned short vendor1; /* vendor unique */

# unsigned short vendor2; /* Retired vendor unique */

# unsigned char serial_no[20]; /* 0 = not_specified */

# unsigned short buf_type; /* Retired */

# unsigned short buf_size; /* Retired, 512 byte increments

# * 0 = not_specified

# */

# unsigned short ecc_bytes; /* for r/w long cmds; 0 = not_specified */

# unsigned char fw_rev[8]; /* 0 = not_specified */

# unsigned char model[40]; /* 0 = not_specified */

# unsigned char max_multsect; /* 0=not_implemented */

# unsigned char vendor3; /* vendor unique */

# unsigned short dword_io; /* 0=not_implemented; 1=implemented */

# unsigned char vendor4; /* vendor unique */

# unsigned char capability; /* (upper byte of word 49)

# * 3: IORDYsup

# * 2: IORDYsw

# * 1: LBA

# * 0: DMA

# */

# unsigned short reserved50; /* reserved (word 50) */

# unsigned char vendor5; /* Obsolete, vendor unique */

# unsigned char tPIO; /* Obsolete, 0=slow, 1=medium, 2=fast */

# unsigned char vendor6; /* Obsolete, vendor unique */

# unsigned char tDMA; /* Obsolete, 0=slow, 1=medium, 2=fast */

# unsigned short field_valid; /* (word 53)

# * 2: ultra_ok word 88

# * 1: eide_ok words 64-70

# * 0: cur_ok words 54-58

# */

# unsigned short cur_cyls; /* Obsolete, logical cylinders */

# unsigned short cur_heads; /* Obsolete, l heads */

# unsigned short cur_sectors; /* Obsolete, l sectors per track */

# unsigned short cur_capacity0; /* Obsolete, l total sectors on drive */

# unsigned short cur_capacity1; /* Obsolete, (2 words, misaligned int) */

# unsigned char multsect; /* current multiple sector count */

# unsigned char multsect_valid; /* when (bit0==1) multsect is ok */

# unsigned int lba_capacity; /* Obsolete, total number of sectors */

# unsigned short dma_1word; /* Obsolete, single-word dma info */

# unsigned short dma_mword; /* multiple-word dma info */

# unsigned short eide_pio_modes; /* bits 0:mode3 1:mode4 */

# unsigned short eide_dma_min; /* min mword dma cycle time (ns) */

# unsigned short eide_dma_time; /* recommended mword dma cycle time (ns) */

# unsigned short eide_pio; /* min cycle time (ns), no IORDY */

# unsigned short eide_pio_iordy; /* min cycle time (ns), with IORDY */

# unsigned short words69_70[2]; /* reserved words 69-70

# * future command overlap and queuing

# */

# unsigned short words71_74[4]; /* reserved words 71-74

# * for IDENTIFY PACKET DEVICE command

# */

# unsigned short queue_depth; /* (word 75)

# * 15:5 reserved

# * 4:0 Maximum queue depth -1

# */

# unsigned short words76_79[4]; /* reserved words 76-79 */

# unsigned short major_rev_num; /* (word 80) */

# unsigned short minor_rev_num; /* (word 81) */

# unsigned short command_set_1; /* (word 82) supported

# * 15: Obsolete

# * 14: NOP command

# * 13: READ_BUFFER

# * 12: WRITE_BUFFER

# * 11: Obsolete

# * 10: Host Protected Area

# * 9: DEVICE Reset

# * 8: SERVICE Interrupt

# * 7: Release Interrupt

# * 6: look-ahead

# * 5: write cache

# * 4: PACKET Command

# * 3: Power Management Feature Set

# * 2: Removable Feature Set

# * 1: Security Feature Set

# * 0: SMART Feature Set

# */

# unsigned short command_set_2; /* (word 83)

# * 15: Shall be ZERO

# * 14: Shall be ONE

# * 13: FLUSH CACHE EXT

# * 12: FLUSH CACHE

# * 11: Device Configuration Overlay

# * 10: 48-bit Address Feature Set

# * 9: Automatic Acoustic Management

# * 8: SET MAX security

# * 7: reserved 1407DT PARTIES

# * 6: SetF sub-command Power-Up

# * 5: Power-Up in Standby Feature Set

# * 4: Removable Media Notification

# * 3: APM Feature Set

# * 2: CFA Feature Set

# * 1: READ/WRITE DMA QUEUED

# * 0: Download MicroCode

# */

# unsigned short cfsse; /* (word 84)

# * cmd set-feature supported extensions

# * 15: Shall be ZERO

# * 14: Shall be ONE

# * 13:6 reserved

# * 5: General Purpose Logging

# * 4: Streaming Feature Set

# * 3: Media Card Pass Through

# * 2: Media Serial Number Valid

# * 1: SMART selt-test supported

# * 0: SMART error logging

# */

# unsigned short cfs_enable_1; /* (word 85)

# * command set-feature enabled

# * 15: Obsolete

# * 14: NOP command

# * 13: READ_BUFFER

# * 12: WRITE_BUFFER

# * 11: Obsolete

# * 10: Host Protected Area

# * 9: DEVICE Reset

# * 8: SERVICE Interrupt

# * 7: Release Interrupt

# * 6: look-ahead

# * 5: write cache

# * 4: PACKET Command

# * 3: Power Management Feature Set

# * 2: Removable Feature Set

# * 1: Security Feature Set

# * 0: SMART Feature Set

# */

# unsigned short cfs_enable_2; /* (word 86)

# * command set-feature enabled

# * 15: Shall be ZERO

# * 14: Shall be ONE

# * 13: FLUSH CACHE EXT

# * 12: FLUSH CACHE

# * 11: Device Configuration Overlay

# * 10: 48-bit Address Feature Set

# * 9: Automatic Acoustic Management

# * 8: SET MAX security

# * 7: reserved 1407DT PARTIES

# * 6: SetF sub-command Power-Up

# * 5: Power-Up in Standby Feature Set

# * 4: Removable Media Notification

# * 3: APM Feature Set

# * 2: CFA Feature Set

# * 1: READ/WRITE DMA QUEUED

# * 0: Download MicroCode

# */

# unsigned short csf_default; /* (word 87)

# * command set-feature default

# * 15: Shall be ZERO

# * 14: Shall be ONE

# * 13:6 reserved

# * 5: General Purpose Logging enabled

# * 4: Valid CONFIGURE STREAM executed

# * 3: Media Card Pass Through enabled

# * 2: Media Serial Number Valid

# * 1: SMART selt-test supported

# * 0: SMART error logging

# */

# unsigned short dma_ultra; /* (word 88) */

# unsigned short trseuc; /* time required for security erase */

# unsigned short trsEuc; /* time required for enhanced erase */

# unsigned short CurAPMvalues; /* current APM values */

# unsigned short mprc; /* master password revision code */

# unsigned short hw_config; /* hardware config (word 93)

# * 15: Shall be ZERO

# * 14: Shall be ONE

# * 13:

# * 12:

# * 11:

# * 10:

# * 9:

# * 8:

# * 7:

# * 6:

# * 5:

# * 4:

# * 3:

# * 2:

# * 1:

# * 0: Shall be ONE

# */

# unsigned short acoustic; /* (word 94)

# * 15:8 Vendor"s recommended value

# * 7:0 current value

# */

# unsigned short msrqs; /* min stream request size */

# unsigned short sxfert; /* stream transfer time */

# unsigned short sal; /* stream access latency */

# unsigned int spg; /* stream performance granularity */

# unsigned long long lba_capacity_2;/* 48-bit total number of sectors */

# unsigned short words104_125[22];/* reserved words 104-125 */

# unsigned short last_lun; /* (word 126) */

# unsigned short word127; /* (word 127) Feature Set

# * Removable Media Notification

# * 15:2 reserved

# * 1:0 00 = not supported

# * 01 = supported

# * 10 = reserved

# * 11 = reserved

# */

# unsigned short dlf; /* (word 128)

# * device lock function

# * 15:9 reserved

# * 8 security level 1:max 0:high

# * 7:6 reserved

# * 5 enhanced erase

# * 4 expire

# * 3 frozen

# * 2 locked

# * 1 en/disabled

# * 0 capability

# */

# unsigned short csfo; /* (word 129)

# * current set features options

# * 15:4 reserved

# * 3: auto reassign

# * 2: reverting

# * 1: read-look-ahead

# * 0: write cache

# */

# unsigned short words130_155[26];/* reserved vendor words 130-155 */

# unsigned short word156; /* reserved vendor word 156 */

# unsigned short words157_159[3];/* reserved vendor words 157-159 */

# unsigned short cfa_power; /* (word 160) CFA Power Mode

# * 15 word 160 supported

# * 14 reserved

# * 13

# * 12

# * 11:0

# */

# unsigned short words161_175[15];/* Reserved for CFA */

# unsigned short words176_205[30];/* Current Media Serial Number */

# unsigned short words206_254[49];/* reserved words 206-254 */

# unsigned short integrity_word; /* (word 255)

# * 15:8 Checksum

# * 7:0 Signature

# */

# };

相关推荐

python读取电脑识别码

多努力就会有多特殊(neverforever)——仌 目标 用python语言,识别电脑机器码,通过授权码,只允许软件运行在唯一电脑上,实现“一机一码”。 注:程序识别的机器码包括: 1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一) 实现方法 软件安装后,运行软件时,通过电脑机器码的唯一性实现授权码的唯一性。 实现过程 运行软件,...

三更雪的博客 1万+

linux c 获取硬盘的序列号

获取硬盘序列号的方法 找到指定硬盘的设备文件(如果是根目录的话,可以通过读取 /etc/mtab 文件获取),打开对应的设备文件。然后使用系统调用ioctl。 在这里 ioctl 的第二个参数为 HDIO_GET_IDENTITY (获得指定文件描述符的标志号) 第三个参数为 struct hd_driveid ,在 linux/hdreg.h 中。 struct hd_driveid 结构

Gino的专栏 1万+

python获取电脑CPU、主板、BIOS、硬盘序列号、主机名、IP、Mac地址

python获取电脑CPU、主板、BIOS、硬盘序列号、主机名、IP、Mac地址、唯一标识符

LDC,公众号【轻松学编程】 2705

获取硬盘的序列号信息

      通过系统接口来获取机器的硬盘信息是编程中常遇见的小问题。       一般情况下,我们常用GetLogicalDrives,GetDriveType这两个API来获取当前系统下,硬盘的逻辑分区信息,以及各个分区的硬件类型。       这次要做的是获取硬盘的系列号信息。       在网上有朋友提供一种以DeviceIoControl函数为核心的办法。通过该函数

MtWinder的专栏 1266

如何通过编程查看电脑硬盘序列号

硬盘序列号是硬盘的唯一标识符,它可以用于在计算机系统中唯一标识一个硬盘设备。在编程中,我们可以使用各种编程语言和操作系统提供的API来获取硬盘序列号。在这种情况下,您可能需要使用特定于操作系统和硬件的方法来获取硬盘序列号。Python是一种功能强大且易于学习的编程语言,它有许多库可以帮助我们执行系统级操作。的函数,该函数通过遍历计算机上的所有硬盘分区来获取硬盘序列号。函数来获取硬盘序列号,并将其打印出来。安装完成后,我们可以开始编写获取硬盘序列号的代码。函数获取硬盘的序列号。库来获取硬盘序列号。

ByteJolt的博客 453

10、Python获取window10 配置信息

基本思:获取window10的主板序列号 cpu序列号 gpu序列号 硬盘序列号 本机MAC地址等 import wmi import re ############ 1. 获取硬件信息,输出 macode # 1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一) global s s = wmi.WMI() # cpu 序列号 def get_CPU_info(): cpu = [] cp = s.Win32_Pr

sxj731533730 940

获取硬盘分区卷的序列号

使用 GetVolumeInformation API获得获取与磁盘卷有关的信息 API说明: VB声明Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolume

3828

不平衡电网下级联H桥STATCOM三层控制策略与Simulink仿真解析

静止同步补偿器(STATCOM)是电能质量治理中的关键装置,而级联H桥拓扑凭借模块化、易扩展等优势,在中高压配电网无功补偿领域应用广泛。当电网出现三相不平衡时,负序分量会引发功率二倍频波动,导致直流侧电容电压振荡、补偿性能下降,甚至引发保护跳闸。围绕这一工程痛点,系统阐述级联H桥STATCOM的三层控制策略:系统级的总电压与无功指令控制、装置级的正负序电流解耦、模块级的电容电压均衡及载波移相PWM调制。结合10kV/±5Mvar仿真案例,演示不平衡故障模拟、控制模型搭建及参数整定方法,为电力电子方向毕业设计

weixin_29164185的博客 333

Python3使用wmi获取系统信息-以获取硬盘分区为例

在python中使用wmi和在c++中使用并没有太多区别,如果考虑兼容性的话个人还是推荐使用winapi方式获取信息,因为xp中默认是不开启wmi的,并且用户或软件可以关闭系统的wmi功能,会出现获取不到数据的情况。 安装所需依赖 pip3 install wmi pip3 install pywin32 代码round(int(), 2)是保留两位小数的功能, py库包含import...

u014101410的博客 2474

电子技术——共栅和共源共栅放大器的高频响应

我们在之前学过无论是是CS放大器还是CE放大器,都可以看做是一个带通(IC低通)滤波器。在高频处的响应收到输入电容 $C_{in}$ 的限制(主要是米勒效应)。因此,若想扩大放大器的带宽,我们必须减小米勒效应,一种方案就是共栅放大器。

jiahonghao2002的博客 4191

再生龙(clonezilla)镜像比目标盘大——基于centos8.5

再生龙恢复到小盘遇到的问题及处理,首先是修改分区大小,进入dracut模式后再尝试恢复临时系统。

u010101453的博客 3701

AI如何帮你一键查询硬盘序列号?告别复杂CMD命令

而AI工具能通过自然语言理解需求,比如直接说"列出所有硬盘的序列号和剩余空间",就能自动生成完整解决方案。最省心的是部署环节——完成开发后点击右上角的部署按钮,系统就自动生成可公开访问的链接,连Nginx配置都帮忙做好了。整个开发过程中最惊喜的是,当我想添加SMART检测功能时,AI不仅给出了Windows和Linux双平台适配方案,还自动标注了各参数的危险阈值。原本需要查三天文档的工作,现在喝杯咖啡的时间就搞定了。现在我们的运维同事都在用这个工具,连非技术岗的同事也能通过简单界面查询设备信息。

SnowflakeJaguar14的博客 929

KAN神经网络实战:如何用Python快速搭建你的第一个可解释性模型

本文提供了使用Python和PyTorch快速搭建首个KAN(Kolmogorov-Arnold Networks)神经网络模型的实战指南。通过对比传统MLP,详细解析了KAN利用可学习的边函数实现更高可解释性的核心原理,并逐步演示了从环境配置、数据准备、核心模块实现到模型训练与可视化的完整流程,帮助开发者掌握这一新兴的可解释性AI模型构建方法。

convnet3designer的博客 477

python获取设备硬件信息_python获取计算机硬件信息

importwmi############ 1. 获取硬件信息,输出 macode#1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一)globalss=wmi.WMI()#cpu 序列号defget_CPU_info(self):cpu=[]cp=s.Win32_Processor()for u incp:cpu.append({"N...

weixin_39641103的博客 1648

01 AUTOSAR CP标准文档阅读指南

01 AUTOSAR CP标准文档阅读指南

汽车软件工程师 | 好奇博主 | 处女座 1139

zabbix深度监控之邮件告警、微信群和微信告警

本文详细介绍了Zabbix监控系统实现邮件告警和微信告警的配置方法。邮件告警部分包含QQ和163邮箱的SMTP服务器配置、消息模板设置、告警流程三步骤(媒介配置、触发器动作、用户设置)。微信告警分为两种方式:企业微信群机器人告警(通过webhook实现)和企业微信应用告警(需创建应用并获取API参数)。两种告警方式都提供了完整的配置流程,包括脚本编写、权限设置、消息模板定制等关键步骤,并特别说明了如何使个人微信接收企业微信告警消息。文章还对比了SMTP、POP3、IMAP三种邮件协议的差异及适用场景。

提供C#相关开发 、云计算、运维测试、网络安全相关技术分享与服务,有意向可联系。 826

【实践】python 机器码 实现一机一码

原文链接: python读取电脑识别码_三更雪的博客-CSDN博客_python获取机器码 机缘巧合下,看见了这篇文章。就copy下来,想运行一下。结果上班看了1,2天代码终于看懂了(我是新手),bug也解决好几天,就想着记录一下,顺便加点注释。 1、引入模块 import wmi import json import base64 from pyDes import * 这里可能引入会报下面的错,我的原因是因为pywin32的版本不对,不在过多赘述,具体查看import win32api.

TaiBai_435_的博客 1万+

记录:解决Ubuntu20.04安装ros报错E: Unable to locate package ros-kinetic-desktop-full【亲测有效】

报错:E: Unable to locate package ros-kinetic-desktop-full.尝试好久一直都无法下载,最后得知真相的我眼泪哗哗的直流。

**My Coding Family** 6万+

python获取计算机硬件信息,python获取计算机硬件信息

importwmi############ 1. 获取硬件信息,输出 macode#1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一)globalss=wmi.WMI()#cpu 序列号defget_CPU_info(self):cpu=[]cp=s.Win32_Processor()for u incp:cpu.append({"N...

weixin_28665677的博客 1020

【施磊】C++课程笔记目录

【C++编程】施磊老师C++笔记目录

GeniusAng的博客 4134

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

python 获取硬件信息_python获取计算机硬件信息

importwmi############ 1. 获取硬件信息,输出 macode#1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一)globalss=wmi.WMI()#cpu 序列号defget_CPU_info(self):cpu=[]cp=s.Win32_Processor()for u incp:cpu.append({"N...

weixin_39683769的博客 265

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

python运行时关闭硬件信息-python获取计算机硬件信息

importwmi############ 1. 获取硬件信息,输出 macode#1.CPU序列号(ID) 2.本地连接 无线局域网 以太网的MAC 3.硬盘序列号(唯一) 4.主板序列号(唯一)globalss=wmi.WMI()#cpu 序列号defget_CPU_info(self):cpu=[]cp=s.Win32_Processor()for u incp:cpu.append({&q...

weixin_39996762的博客 357

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

python3获取磁盘序列号并进行加密验证

一直有想过一个问题,如何做一个类似于授权的程序,于是通过网上搜索学习,有了接下来的程序。 如何利用机器码进行注册加密验证:1:选取c盘序列号,一般每台电脑的c盘序列号都不一样 2:将序列号进行des加密并用base64编码 3:解密验证 import base64 import win32api from pyDes import * import binascii class register: def __init__(self): self.Des_Key = b"BHC#@

qq_43302174的博客 2093

python-自动篇-运维-根据计算机硬盘、主板、CPU生成注册信息

本实例需要使用WMI模块,所以需要安装WMI模块。在安装WMI模块之前,先要安装pywin32模块,WMI模块需要win32api的支持。

stqer的博客 2060

软件授权码方案(附Python示例代码)

思路: 软件安装后,运行软件时,通过电脑机器码的唯一性实现授权码的唯一性。(机器码:由cpu序列号、硬盘序列号、mac地址、主板序列号组成的字符串截取部分字符) 方案: 1、运行软件,检测注册文件,若未检测到注册文件或者注册文件中的注册码与机器码进行DES+base64加密后的编码不一致,则提醒用户输入注册码或重新获取注册码。重新获取注册码会将程序运行后显示的机器组合码 发送给指定管理员,管...

chenxy02的博客 1万+
上一篇: mysql企业版多少钱_阿里云企业邮箱多少钱?免费版和付费版有何区别?
下一篇: 2条电信宽带 并线_考到驾照,这20条安全行车的知识,非常重要_
weixin_39752828
博客等级 码龄9年 63粉丝 150原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址