在 Linux 命令行上以编程方式删除所有蓝牙设备

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17580347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:13:11  来源:igfitidea点击:

Programmatically removing all bluetooth devices on the Linux command line

linuxbluetoothbluezhci

提问by user2570136

I am able to scan for all available bluetooth devices with hcitool or with my C program.

我可以使用 hcitool 或我的 C 程序扫描所有可用的蓝牙设备。

I can pair the device using it's address with a simple-agent python script.

我可以使用它的地址将设备与简单代理 python 脚本配对。

I would like to know if I can also remove the paired device using either hcitool, hciconfig or some kind of bluetooth command.

我想知道我是否也可以使用 hcitool、hciconfig 或某种蓝牙命令删除配对的设备。

I know the information of detected devices for the hci0 controller is stored in /var/lib/bluetooth/XX:XX:XX:XX:XX:XX, where XX:XX:XX:XX:XX is the address of the hci controller.

我知道 hci0 控制器检测到的设备信息存储在 /var/lib/bluetooth/XX:XX:XX:XX:XX:XX 中,其中 XX:XX:XX:XX:XX 是 hci 控制器的地址.

This would be useful for testing pairing, connecting and disconnecting devices.

这对于测试配对、连接和断开设备很有用。

回答by ashish

bluez-test-device remove XX:XX:XX:XX:XX:XX

bluez-test-device 删除 XX:XX:XX:XX:XX:XX

回答by B?ови?

If you install the bluez-toolspackage, run this to unpair a bluetooth device :

如果您安装了该bluez-tools软件包,请运行此命令以取消配对蓝牙设备:

bt-device -r xx:xx:xx:xx:xx:xx

where xx:xx:xx:xx:xx:xxis the address of the paired device.

xx:xx:xx:xx:xx:xx配对设备的地址在哪里。

回答by Levent Divilioglu

As it is mentioned above on ashish's answer, you can us bluez-test-device to remove the device which that you already know its mac address. So the problem is to parse the mac address of the added devices.

正如上面在 ashish 的回答中提到的,您可以使用 bluez-test-device 删除您已经知道其 mac 地址的设备。所以问题是解析添加设备的mac地址。

With python or c or whatever you use,

使用 python 或 c 或任何你使用的,

1) list the devices with;

1) 列出设备;

bluez-test-device list

and parse the output and get all the MAC addresses of the devices, add them to a list.

并解析输出并获取设备的所有 MAC 地址,将它们添加到列表中。

2) disconnect and remove the devices;

2) 断开并移除设备;

bluez-test-device disconnect <MAC ADDRESS>
bluez-test-device remove <MAC ADDRESS>