我可以使用 hcitool 或我的 C 程序扫描所有可用的蓝牙设备。
我可以使用设备地址与简单代理 python 脚本将设备配对。
我想知道是否也可以使用 hcitool、hciconfig 或某种蓝牙命令删除配对的设备。
我知道 hci0 控制器检测到的设备信息存储在 /var/lib/bluetooth/XX:XX:XX:XX:XX:XX 中,其中 XX:XX:XX:XX:XX 是 hci 的地址控制器。
这对于测试配对、连接和断开设备非常有用。
对于使用 Ubuntu 20.04 的用户,这里是使用 bluetoothctl 命令的相同命令
#!/bin/bash
for device in $(bluetoothctl devices | grep -o "[[:xdigit:]:]\{8,17\}"); do
echo "removing bluetooth device: $device | $(bluetoothctl remove $device)"
done
bluez-测试设备删除 XX:XX:XX:XX:XX:XX
如果您安装了
bluez-tools
软件包,请运行此命令来取消蓝牙设备配对:
bt-device -r xx:xx:xx:xx:xx:xx
其中
xx:xx:xx:xx:xx:xx
是配对设备的地址。
正如上面 ashish 的回答所提到的,您可以使用 bluez-test-device 来删除您已经知道其 mac 地址的设备。所以问题就是解析添加设备的mac地址。
使用 python 或 c 或任何你使用的东西,
1) 列出设备;
bluez-test-device list
并解析输出并获取设备的所有 MAC 地址,将它们添加到列表中。
2) 断开并移除设备;
bluez-test-device disconnect <MAC ADDRESS>
bluez-test-device remove <MAC ADDRESS>
使用 bluetoothctl 二进制命令:
for device in $(bluetoothctl devices | grep -vEi '(o que mais vc quer deixar aqui|samsung|jbl|wireless)' | awk '{print $2}'); do bluetoothctl remove $device; done
所有这些答案都没有回答标题“删除所有蓝牙设备”
我编写了这个小 bash 脚本来删除
bt-device -l
中列出的所有蓝牙设备
#!/bin/bash
for device in $(bt-device -l | grep -o "[[:xdigit:]:]\{11,17\}"); do
echo "removing bluetooth device: $device | $(bt-device -r $device)"
done
<fileName>.sh
的新文件并粘贴上面的代码。chmod +x <fileName>
使脚本可执行./<fileName>.sh
类似于 Jesse de gans 的答案,这里有一个单行代码,用于 bt-device 和 bluetoothctl 的所有设备断开。
# disconnect all devices using bt-device
for device in `bt-device -l`; do [[ "$device" =~ ([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2}) ]] && bt-device -d $(echo $device | sed 's/[()]//g'); done
# disconnect all devices using bluetoothctl
for device in `bluetoothctl paired-devices`; do [[ "$device" =~ ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$ ]] && bluetoothctl disconnect $device; done
对于 bt-device 来说,需要做更多的工作,因为 MAC 地址被括在括号中
()
所以我们需要使用 sed 来剥离它们。