如何在 Python 中找到可见的蓝牙设备?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21000680/
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
How to find visible bluetooth devices in Python?
提问by Ufoguy
I need to find the list of visible Bluetooth devices with their respective details in the range of my Bluetooth modem. I only need to do Bluetooth 2.0 and below. I don't need to do Bluetooth 4.0.
我需要在我的蓝牙调制解调器范围内找到可见蓝牙设备的列表以及它们各自的详细信息。我只需要做蓝牙2.0及以下。我不需要做蓝牙4.0。
Like you do on an Android phones using "Search for devices".
就像您在 Android 手机上使用“搜索设备”所做的那样。
I'm sorry I can't give any code I tried because I don't know how to do Bluetooth with python.
很抱歉,我无法提供我尝试过的任何代码,因为我不知道如何使用 python 进行蓝牙。
采纳答案by Kobi K
蓝蓝兹:
from bluetooth import *
print "performing inquiry..."
nearby_devices = discover_devices(lookup_names = True)
print "found %d devices" % len(nearby_devices)
for name, addr in nearby_devices:
print " %s - %s" % (addr, name)
See also Programming Bluetooth using Python
另请参阅使用 Python 编程蓝牙
The important thing is you can use lookup_names = True
重要的是你可以使用 lookup_names = True
from bluez Docs:
来自 bluez 文档:
if lookup_names is False, returns a list of bluetooth addresses.
if lookup_names is True, returns a list of (address, name) tuples
回答by zero_dev
You can use PyBluez:
您可以使用 PyBluez:
import bluetooth
nearby_devices = bluetooth.discover_devices()

