Python Stick USB Serial Number

I am trying to get the serial number (or any unique hardware identifier) ​​of a USB drive using Python on Linux. I started with the recipe I found in this SO question .

The code in this link is great for hard drives. For example, on my internal SSD, it returns:

  $ sudo python clusterTool.py / dev / sda
 Hard Disk Model: SAMSUNG SSD PM810 2.5 "7mm 256GB
   Serial Number: S0NUNYAB503012

rocking chair!

However, when I run it on a flash card, I get an error message from ioctl that fails without binding to the following python trace:

  $ 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

The file assumes that they are similar to each other:

  $ file / dev / sd {a, b}
 / dev / sda: block special
 / dev / sdb: block special

I'm not sure how they differ, but they clearly diverge. What is the difference between these devices, and is there any way to get their identifiers evenly?

+4
source share
1 answer

This can help http://www.roman10.net/linux-get-udev-device-information-in-pythonpyudev/ using the pudon and python installation tools with syspath.

0
source

Source: https://habr.com/ru/post/1501534/


All Articles