[英]USB Stick Serial number in Python
I am trying to get the serial number (or any unique hardware based identifier) of a USB flash drive using Python on Linux. 我试图在Linux上使用Python获取USB闪存驱动器的序列号(或任何独特的基于硬件的标识符)。 I started with the recipe I found in this SO question .
我从这个SO问题中找到的配方开始。
The code in that link work great for fixed hard drives. 该链接中的代码非常适合固定硬盘驱动器。 For example on my internal laptop SSD it returns:
例如,在我的内置笔记本电脑SSD上,它返回:
$ sudo python clusterTool.py /dev/sda Hard Disk Model: SAMSUNG SSD PM810 2.5" 7mm 256GB Serial Number: S0NUNYAB503012
Rocking! 摇摆!
However when I run it on a flash-stick I get a error from ioctl that is getting ungracefully coherced to the following python trace: 然而,当我在闪存棒上运行它时,我从ioctl得到一个错误,该错误正在被非常地跟随到以下python跟踪:
$ sudo python clusterTool.py /dev/sdb Traceback (most recent call last): File "clusterTool.py", line 21, in buf = fcntl.ioctl(fd, HDIO_GET_IDENTITY, " " * sizeof_hd_driveid) IOError: [Errno 22] Invalid argument
File suggests they are the same sort of beast: 文件表明他们是同一种野兽:
$ file /dev/sd{a,b} /dev/sda: block special /dev/sdb: block special
I am not sure how they differ, but they clearly diverge somewhere. 我不确定它们有何不同,但它们显然在某处分歧。 What is the difference between these devices, and is there any way I uniformly get their identifiers?
这些设备之间有什么区别,有什么办法可以统一获取标识符吗?
这可能有助于http://www.roman10.net/linux-get-udev-device-information-in-pythonpyudev/使用pypathv和python设置工具与syspath。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.