本文整理汇总了Python中bluetooth.discover_devices方法的典型用法代码示例。如果您正苦于以下问题:Python bluetooth.discover_devices方法的具体用法?Python bluetooth.discover_devices怎么用?Python bluetooth.discover_devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bluetooth
的用法示例。
在下文中一共展示了bluetooth.discover_devices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def scan(self, device_id: Optional[int] = None, duration: int = 10) -> BluetoothScanResponse:
"""
Scan for nearby bluetooth devices
:param device_id: Bluetooth adapter ID to use (default configured if None)
:param duration: Scan duration in seconds
"""
from bluetooth import discover_devices
if device_id is None:
device_id = self.device_id
self.logger.debug('Discovering devices on adapter {}, duration: {} seconds'.format(
device_id, duration))
devices = discover_devices(duration=duration, lookup_names=True, lookup_class=True, device_id=device_id,
flush_cache=True)
response = BluetoothScanResponse(devices)
self._devices = response.devices
self._devices_by_addr = {dev['addr']: dev for dev in self._devices}
self._devices_by_name = {dev['name']: dev for dev in self._devices if dev.get('name')}
return response
示例2: findDevs
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def findDevs(opts):
global foundDevs
devList = bluetooth.discover_devices(lookup_names=True)
repeat = range(0, int(opts.repeat))
for (dev, name) in devList:
if dev not in foundDevs:
name = str(bluetooth.lookup_name(dev))
printDev(name, dev)
foundDevs.append(dev)
for i in repeat:
sendFile(dev, opts.file)
continue
if opts.spam:
for i in repeat:
sendFile(dev, opts.file)
示例3: scandevices
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def scandevices(self):
logging.warning("Searching for devices...\n"
"It may take time, you'd better specify mac address to avoid a scan.")
valid_names = ['MiaoMiaoJi', 'Paperang']
nearby_devices = discover_devices(lookup_names=True)
valid_devices = filter(lambda d: len(d) == 2 and d[1] in valid_names, nearby_devices)
if len(valid_devices) == 0:
logging.error("Cannot find device with name %s." % " or ".join(valid_names))
return False
elif len(valid_devices) > 1:
logging.warning("Found multiple valid machines, the first one will be used.\n")
logging.warning("\n".join(valid_devices))
else:
logging.warning(
"Found a valid machine with MAC %s and name %s" % (valid_devices[0][0], valid_devices[0][1])
)
self.address = valid_devices[0][0]
return True
示例4: btscanning
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def btscanning():
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M')
if args.gpstrack:
gpslat = str(gpsd.fix.latitude)
gpslong = str(gpsd.fix.longitude)
else:
gpslat = "nil"
gpslong = "nil"
devices = bluetooth.discover_devices(duration=1, lookup_names = True)
for addr, name in devices:
if addr not in btclients:
if not args.quiet:
print W+ '[' +R+ 'Bluetooth Client' +W+ ':' +B+ addr +W+ '] [' +G+ 'Name' +W+ ': ' +O+ name +W+ ']'
btclients.append(addr)
# Logging info
fields = []
fields.append(st) # Log Time
fields.append('BT') # Log Client or AP
fields.append(addr) # Log Mac Address
fields.append('nil') # Log Device Manufacture
fields.append(name) # Log BT Name
fields.append('nil') # Log Crypto
fields.append(gpslat) # Log GPS data
fields.append(gpslong) # Log GPS data
fields.append(args.location) # Log Location data
fields.append('nil') # RSSI
logger.info(args.delimiter.join(fields))
示例5: scan
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def scan():
'''
Scan for bluetooth-devices
:return: list of bluetooth-devices
:rtype: [blueproximity.device.BluetoothDevice]
'''
def _scan():
for mac, name in bluetooth.discover_devices(lookup_names=True):
yield BluetoothDevice(mac=mac, name=name)
return list(_scan())
示例6: find_bricks
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def find_bricks(host=None, name=None):
for h, n in bluetooth.discover_devices(lookup_names=True):
if _check_brick(host, h) and _check_brick(name, n):
yield BlueSock(h)
示例7: test_bluetooth_2_raspberry_can_find_nxt
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def test_bluetooth_2_raspberry_can_find_nxt(self):
blue_list = blue.discover_devices()
self.assertIn(self.ID, blue_list)
示例8: main
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def main():
print("searching for devices\n")
results = bluetooth.discover_devices(duration=20, lookup_names=True)
vuln_devices = []
if (results):
for addr, name in results:
vulnerable = is_device_vulnerable(addr)
if vulnerable:
vuln_devices.append((addr,name))
print("%s %s is " % (addr, name) + bcolors.RED + "vulnerable" + bcolors.ENDC)
else:
print("%s %s is" + bcolors.GREEN + "patched" + bcolors.ENDC)
if len(vuln_devices) > 0:
print(bcolors.ORANGE + "\nExploit" + bcolors.ENDC + "\n" + "-"*35)
for idx, dev in enumerate(vuln_devices):
print("[%s] %s %s" % (idx, dev[0], dev[1]))
selection = input(bcolors.GREEN + "\nchoice: " + bcolors.ENDC)
try:
sel = int(selection)
addr = vuln_devices[sel][0]
cve20170785.exploit(addr)
except:
print("Invalid selection")
else:
print(bcolors.GREEN + "No vulnerable devices found!" + bcolors.ENDC)
示例9: bluetooth_classic_scan
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def bluetooth_classic_scan(timeout=10):
"""
This scan finds ONLY Bluetooth classic (non-BLE) devices in *pairing mode*
"""
return bt.discover_devices(duration=scansec, flush_cache=True, lookup_names=True)
示例10: discover
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def discover():
print("Scanning for devices ...")
if usingBluetooth:
devices = bluetooth.discover_devices()
print(devices)
if usingLightBlue:
devices = lightblue.finddevices()
print(devices)
return devices
示例11: run
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def run(self):
print("Searching devices...")
duration = int(self.args["timeout"])
devices = discover_devices(
duration=duration, lookup_names=True, flush_cache=True, lookup_class=True)
msg = f"found {len(devices)} devices"
print_info(msg)
print("-"*len(msg))
for addr, name, cl in devices:
try:
print_info(f"{addr} - {name} ({hex(cl)})")
except UnicodeEncodeError:
print_info(f"{addr} - {name.encode('utf-8', 'replace')} ({hex(cl)})")
示例12: run
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def run(self):
print_info("Searching bluetooth devices to check MAC...")
devices = discover_devices(lookup_names=True, lookup_class=True)
device_name = None
device_class = None
for mac, name, cl in devices:
if self.args["bmac"] == mac:
print_info("A nearby device has been found")
device_name = name
device_class = hex(cl)
break
if not device_name:
print_info("No nearby device found")
if self.args['name']:
device_name = self.args['name']
else:
print_error("We can't find the name")
return
if not device_class:
if self.args['class']:
device_class = self.args['class']
else:
print_error("We can't find the profile")
return
print_info("Trying to change name and MAC")
result = system(f"apps/spooftooph -i {self.args['iface']} -a {self.args['bmac']}")
if int(result) == 0:
print_ok("Done!")
print_info("Starting Bluetooth service to allow connections")
self._start_service(device_name, device_class)
else:
print_error("Execution fault...")
示例13: scan_button_clicked
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def scan_button_clicked(self, widget):
self.quit_button.set_sensitive(False)
self.scan_button.set_sensitive(False)
# self.chat_button.set_sensitive(False)
self.discovered.clear()
for addr, name in bluetooth.discover_devices (lookup_names = True):
self.discovered.append ((addr, name))
self.quit_button.set_sensitive(True)
self.scan_button.set_sensitive(True)
# self.chat_button.set_sensitive(True)
示例14: btscanning
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def btscanning():
devices = bluetooth.discover_devices(duration=1, lookup_names = True)
for addr, name in devices:
if addr not in btclients:
print W+ '[' +R+ 'Bluetooth Client' +W+ ':' +B+ addr +W+ '] [' +G+ 'Name' +W+ ': ' +O+ name +W+ ']'
btclients.append(addr)
示例15: search
# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import discover_devices [as 别名]
def search():
print "searching for devices"
devices = bluetooth.discover_devices(duration=20, lookup_names = True)
return devices