28 lines
849 B
Python
28 lines
849 B
Python
import pyudev
|
|
|
|
|
|
def main() -> None:
|
|
context = pyudev.Context()
|
|
|
|
monitor = pyudev.Monitor.from_netlink(context)
|
|
monitor.filter_by(subsystem="block")
|
|
|
|
print("Waiting for disks...")
|
|
|
|
for device in iter(monitor.poll, None):
|
|
if device.action == "add" and device.device_type == "disk":
|
|
print("\nDisk connected")
|
|
print(f"Device: {device.device_node}")
|
|
print(f"Name: {device.sys_name}")
|
|
print(f"Model: {device.get('ID_MODEL', 'Unknown')}")
|
|
print(f"Serial: {device.get('ID_SERIAL_SHORT', 'Unknown')}")
|
|
print(f"Bus: {device.get('ID_BUS', 'Unknown')}")
|
|
|
|
elif device.action == "remove" and device.device_type == "disk":
|
|
print("\nDisk disconnected")
|
|
print(f"Name: {device.sys_name}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|