有没有一种程序化的方法来查看被阻止的蓝牙设备



设备可以这样被阻止:bluetoothctl block FC:69:47:7C:9D:A3

是否有一种编程方法来列出已经被阻止的设备?

与BlueZ蓝牙堆栈接口的记录方法是使用D-Bus API。如果D-Bus API语言具有D-Bus绑定,则该语言允许大多数语言与其接口。

下面是一个使用Python和pydbus库的示例:

import pydbus
dev_iface = 'org.bluez.Device1'
bus = pydbus.SystemBus()
mngr = bus.get('org.bluez', '/')
mngd_objs = mngr.GetManagedObjects()
for path, info in mngd_objs.items():
blocked = info.get(dev_iface, {}).get('Blocked')
if blocked is not None:
address = info.get(dev_iface, {}).get('Address')
print(f'[{address}] is {"Blocked" if blocked else "Not Blocked"}')

BlueZ设备API记录在:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/device-api.txt

是,检查info文件:

grep Blocked /var/lib/bluetooth/*/FC:69:47:7C:9D:A3/info

它将返回:

Blocked=true

相关内容

最新更新