linux - USB端口监控
问题描述
我需要监控 Windows 和 Linux 计算机的 USB 端口,以了解是否连接了笔式驱动器。
我怎么做?
我需要它通过 Linux 脚本或 Windows。
解决方案
您可以使用 Windows 上的 WMI 事件(仅在 Windows上,因为 WMI,Windows Management Instrumentation 仅在 Windows 上可用)在设备状态更改时执行操作。
假设您在 Windows 上,并使用 PowerShell,以下是您在DeviceChangeEvent期间触发事件的方式,例如添加 USB 驱动器时。
Register-WMIEvent -query "Select * From Win32_DeviceChangeEvent where EventType = '2'" `
-action {
#Do Something when a device is added
Write-host "Device added at $(Get-date)"
}
当我插入一个连接了很多端口和设备的 USB 集线器时,我看到的是:
Device added at 06/10/2021 09:27:59
Device added at 06/10/2021 09:27:59
Device added at 06/10/2021 09:28:00
Device added at 06/10/2021 09:28:00
Device added at 06/10/2021 09:28:00
推荐阅读
- java - 如果我在 spring 的 common 类中编写所有依赖项怎么办?它会导致实时现场项目中的内存问题吗?
- mysql - MySQL 将字符串转换为 varbinary
- python - Matlab和Python中的浮点数有什么区别?
- mysql - 基于上次更新的组的 SQL 查询
- ruby-on-rails - 如何使用 cocoon 同时创建父元素和嵌套元素
- typescript - 具有重载函数的类型推断
- tensorflow - 图像馈送到深度神经网络
- cordova - Ionic 3-如何在设备默认浏览器中打开外部 url
- c++ - 我的随机生成器是否无法正常工作,或者我在决定人类/骷髅是否击中对手时是否存在错误?
- sql-server - SQL Server Service Broker - 端点上的证书就足够了吗?