Skip to content

radialmonster/drive-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Drive ID Monitor

This Python script (driveid.py) is designed to monitor physical disk drives on a Windows machine in real-time. It detects when a USB drive or other removable storage device is plugged in or unplugged, and for newly connected drives, it attempts to list the files and folders in its root directory.

Features

  • Real-Time Monitoring: Continuously checks for changes in connected physical disk drives.
  • Plug/Unplug Detection: Clearly notifies the user when a device is plugged in or unplugged.
  • Drive Content Listing (for new drives): Attempts to list the root-level files and folders of newly detected drives.
  • Robust Error Handling: Gracefully handles common issues like permission denied errors, unformatted drives, or inaccessible paths during file listing, preventing script crashes.
  • Efficient WMI Usage: Optimizes WMI (Windows Management Instrumentation) calls by initializing the client once and reusing it, reducing system overhead.

Why It's Useful

  • Security Auditing: Keep track of unauthorized drive connections.
  • System Diagnostics: Monitor drive activity and detect changes in storage devices.
  • Automation Trigger: Can be extended to trigger other actions upon drive connection/disconnection.

Setup and Installation

  1. Clone the Repository:

    git clone <repository-url>
    cd drive-id
  2. Install Dependencies: This script relies on the wmi Python package. Install it using pip:

    pip install -r requirements.txt

    (This will install the wmi package, as specified in requirements.txt).

  3. Run the Script: Execute the script from your terminal or command prompt:

    python src/driveid.py
  4. Monitor Output: The script will start monitoring immediately, displaying information about any drive changes in real-time. Press Ctrl+C to stop the script.

Example Output

Press 'Ctrl+C' to quit the program at any time.
Scanning initial drives...
Monitoring for changes...
Device \\.\PHYSICALDRIVE1: was PLUGGED IN
Contents of drive D:\
  [Folder] MyPhotos
  [File]   document.txt
Device \\.\PHYSICALDRIVE1 (Drive D:): was UNPLUGGED

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributions

Contributions are welcome! Feel free to open an issue or submit a pull request with your improvements or bug fixes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages