s4bba7

List USB devices IDs

Apr 30th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # author: s4bba7
  3. # ver: 1.0
  4.  
  5. # Start this script in a console and unplug USB device. It should print one or more device's IDs - pick one.
  6. # Package pyudev have to be installed.
  7.  
  8. import functools
  9. import os.path
  10. import pyudev
  11. import subprocess
  12.  
  13.  
  14. def main():
  15.     BASE_PATH = os.path.abspath(os.path.dirname(__file__))
  16.     path = functools.partial(os.path.join, BASE_PATH)
  17.     call = lambda x, *args: subprocess.call([path(x)] + list(args))
  18.  
  19.     context = pyudev.Context()
  20.     monitor = pyudev.Monitor.from_netlink(context)
  21.     monitor.filter_by(subsystem='usb')
  22.     monitor.start()
  23.  
  24.     for device in iter(monitor.poll, None):
  25.         print(device)
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     main()
Advertisement
Add Comment
Please, Sign In to add comment