1

In Python 2, I'm looking to get the make/model of a device, such as an Ethernet card, hard drive, CD/DVD/BD drive, etc. I have no idea where to start, and the closest thing a Google search can come up with is detecting when a disc is inserted into a drive or getting the name of a USB device.

For example, I'd look to retrieve a name such as ST1500DM003-9YN16G (this is a HDD) or VirtualBox Host-Only Ethernet Adapter (this is an Ethernet adapter) from the system. Requiring admin privileges isn't an issue, as the program that this'll be used in requires admin privs for other operations anyway.

  • I don't know how exactly to do this, but you could probably get most/all of this info from the command line, and Python can get the output of commands. How to do that is [here](https://stackoverflow.com/questions/4760215), but I'm not quite sure what commands would have to be run, depends on the OS I'm sure. Hope this is a start. – nedla2004 Aug 16 '18 at 01:19
  • 1
    As far as I know, there's no cross-platform library that wraps all of this up. There are two different Windows-specific ways to get this info, one Mac-specific way, one Linux-specific way, and one semi-generic POSIX (everything but Windows) way. All of them can be accessed via either running a command-line tool, opening and reading a file in a special location, or making a web service request, but there are probably libraries on PyPI that wrap up the more painful ones. – abarnert Aug 16 '18 at 01:45
  • @abarnert If you can point me to the POSIX and Windows ways, that'd be really helpful. – Yeniaul Adrianad Sep 24 '18 at 01:42
  • For Googlers, on Windows, the following block will return a NULL-separated list of all device names: `>>>import win32file` `>>>win32file.QueryDosDevice(None)` – Yeniaul Adrianad Sep 27 '18 at 21:17

0 Answers0