1

How to get the USB information like Manufacture Name, Size etc? I am using Ubuntu 16. and Python 2.7.12

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Fazil
  • 51
  • 2
  • 4

2 Answers2

0

Have you tried something like this :

busses = usb.busses()
for bus in busses:
   devices = bus.devices
   for dev in devices:
       print (repr(dev))
       print("manufacturer", dev.iManufacturer)
       print("Size", dev.iSize) 

NOTE : I think it will work only when you are connected one usb at a time

Vikas Periyadath
  • 3,088
  • 1
  • 21
  • 33
  • I got error while executing below code import usb busses = usb.busses() for bus in busses: devices = bus.devices for dev in devices: print (repr(dev)) print("manufacturer", dev.iManufacturer) print("Size", dev.iSize) Error:- ('manufacturer', 0) Traceback (most recent call last): File "getusbinfo.py", line 8, in print("Size", dev.iSize) AttributeError: 'Device' object has no attribute 'iSize' – Fazil Jan 22 '18 at 06:04
  • Can you just refer here : https://stackoverflow.com/questions/25494086/retrieve-usb-information-using-pyudev-with-device-name .... there capacity is just mean to size. – Vikas Periyadath Jan 22 '18 at 06:25
  • how to get the usb info using by pyusb – Fazil Jan 22 '18 at 06:55
  • you can use `import usb.core dev = usb.core.find(find_all=True)` to find USB devices. But I'am not sure about it can give result of size . For more : https://www.orangecoat.com/how-to/use-pyusb-to-find-vendor-and-product-ids-for-usb-devices – Vikas Periyadath Jan 22 '18 at 07:06
  • So I think you can try using pyudev like the answer in the [first link](https://stackoverflow.com/questions/25494086/retrieve-usb-information-using-pyudev-with-device-name). – Vikas Periyadath Jan 22 '18 at 07:16
0

with this you can print all USB String Descriptors in pyusb : Manufacturer String Descriptor, Product String Descriptor, Serial Number String Descriptor ( for all USB devices, including the host controllers ) cf https://www-user.tu-chemnitz.de/~heha/viewchm.php/hs/usb.chm/usb5.htm

import usb

busses = usb.busses()
for bus in busses:
    devices = bus.devices
    for dev in devices:

        manufacturer = usb.util.get_string(dev.dev, dev.dev.iManufacturer)
        print str(manufacturer)
        product = usb.util.get_string(dev.dev, dev.dev.iProduct)
        print str(product)
        serialnumber = usb.util.get_string(dev.dev, dev.dev.iSerialNumber)
        print str(serialnumber)
        print('\n')

you have to call this as root / with sudo else you get ValueError: The device has no langid error

other USB attributes you can print with their names :

import usb

busses = usb.busses()
for bus in busses:
    devices = bus.devices
    for dev in devices:

        print "  Device class:",dev.dev.bDeviceClass
        print "  Device sub class:",dev.dev.bDeviceSubClass
        print "  Device protocol:",dev.dev.bDeviceProtocol
ralf htp
  • 9,149
  • 4
  • 22
  • 34