Home > Mobile >  Is there a way in bluetoothctl to view devices that are blocked?
Is there a way in bluetoothctl to view devices that are blocked?

Time:12-16

A device can be blocked like so: bluetoothctl block FC:69:47:7C:9D:A3

Is there a way to list devices which have already been blocked?

CodePudding user response:

Yes, check the info file:

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

It will return:

Blocked=true

CodePudding user response:

The documented way to interface with the BlueZ Bluetooth stack is with the D-Bus API. The D-Bus API allows most languages to interface with it if the language has D-Bus bindings.

Here is an example using Python and the pydbus library:

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"}')

The BlueZ device API is documented at:

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

  • Related