USB Device Information List

  • Share this:

Code introduction


This function lists all USB devices connected to the computer, including the manufacturer, product name, serial number, and category of the device.


Technology Stack : PyUSB

Code Type : Function

Code Difficulty : Intermediate


                
                    
import usb.core
import usb.util

def list_usb_devices():
    # List all USB devices connected to the computer
    devices = usb.core.find(find_all=True)
    device_list = []
    for device in devices:
        device_list.append({
            'vendor_id': device.idVendor,
            'product_id': device.idProduct,
            'manufacturer': usb.util.get_string(device, device.iManufacturer),
            'product': usb.util.get_string(device, device.iProduct),
            'serial_number': usb.util.get_string(device, device.iSerialNumber),
            'class': usb.util.get_string(device, device.iProductClass)
        })
    return device_list                
              
Tags: