Python bluetooth.discover_devices() Examples

The following are 15 code examples of bluetooth.discover_devices(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bluetooth , or try the search function .
Example #1
Source File: bluetoothObexSpam.py    From Offensive-Security-Certified-Professional with MIT License 9 votes vote down vote up
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) 
Example #2
Source File: __init__.py    From platypush with MIT License 6 votes vote down vote up
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 
Example #3
Source File: peanuts.py    From peanuts with MIT License 5 votes vote down vote up
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)) 
Example #4
Source File: device.py    From Blueproximity with GNU General Public License v2.0 5 votes vote down vote up
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()) 
Example #5
Source File: bluesock.py    From nxt-python with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #6
Source File: test_bluetooth.py    From self_driving_pi_car with MIT License 5 votes vote down vote up
def test_bluetooth_2_raspberry_can_find_nxt(self):
        blue_list = blue.discover_devices()
        self.assertIn(self.ID, blue_list) 
Example #7
Source File: bluebornescan.py    From blueborne with MIT License 5 votes vote down vote up
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) 
Example #8
Source File: message_process.py    From miaomiaoji-tool with MIT License 5 votes vote down vote up
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 
Example #9
Source File: bluetooth_scan.py    From pybluez-examples with MIT License 5 votes vote down vote up
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) 
Example #10
Source File: bluetooth.py    From peach with Mozilla Public License 2.0 5 votes vote down vote up
def discover():
    print("Scanning for devices ...")

    if usingBluetooth:
        devices = bluetooth.discover_devices()
        print(devices)

    if usingLightBlue:
        devices = lightblue.finddevices()
        print(devices)

    return devices 
Example #11
Source File: bluetooth.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
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)})") 
Example #12
Source File: mac-spoof.py    From HomePWN with GNU General Public License v3.0 5 votes vote down vote up
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...") 
Example #13
Source File: bluezchat.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
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) 
Example #14
Source File: peanuts.py    From Peanuts with MIT License 5 votes vote down vote up
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) 
Example #15
Source File: bluebornescan.py    From blueborne-scanner with MIT License 5 votes vote down vote up
def search():         
    print "searching for devices"
    devices = bluetooth.discover_devices(duration=20, lookup_names = True)
    return devices