Python bluetooth.find_service() Examples
The following are 10
code examples of bluetooth.find_service().
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: sdp_scan.py From bluescan with GNU General Public License v3.0 | 6 votes |
def scan(self, addr:str): print(INFO, 'Scanning...') exitcode, output = subprocess.getstatusoutput('sdptool records --xml ' + addr) if exitcode != 0: sys.exit(exitcode) # print('[DEBUG] output:', output) self.parse_sdptool_output(output) # services = find_service(address=addr) # # print(services) # # print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') # for service in services: # print('Name:', service['name'] ) # print('ProtocolDescriptorList', service['protocol']) # print('channel/PSM', service['port']) # print('ServiceClassIDList:', service['service-classes']) # print('Profiles:', service['profiles']) # print('Description:', service['description']) # print('Provider:', service['provider']) # print('ServiceID', service['service-id']) # print()
Example #2
Source File: dirtytooth.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def connect(device_address): d = bluetooth.find_service(address=device_address, uuid="1130") if not d: logging.error('No Phonebook service found.') raise Exception('No Phonebook service found.') port = d[0]["port"] # Use the generic Client class to connect to the phone. c = client.Client(device_address, port) uuid = b'\x79\x61\x35\xf0\xf0\xc5\x11\xd8\x09\x66\x08\x00\x20\x0c\x9a\x66' # result = c.connect(header_list=[headers.Target(uuid)]) try: c.connect(header_list=[headers.Target(uuid)]) return c except: logging.error('Failed to connect to phone.') raise Exception('Failed to connect to phone.') # if not isinstance(result, responses.ConnectSuccess): # logging.error('Failed to connect to phone.') # raise Exception('Failed to connect to phone.') # return c
Example #3
Source File: bt.py From pyescpos with Apache License 2.0 | 6 votes |
def find_rfcomm_port(address): _check_lib_bluetooth() services = bluetooth.find_service(address=address) if not services: raise BluetoothPortDiscoveryError( 'cannot find address: {!r}'.format(address) ) for service in services: if service['host'] == address and service['protocol'] == 'RFCOMM': return service['port'] raise BluetoothPortDiscoveryError( 'cannot find RFCOMM port for address: {!r}'.format(address) )
Example #4
Source File: mitm.py From btproxy with GNU General Public License v3.0 | 6 votes |
def safe_connect(self,target): """ Connect to all services on target as a client. """ services = bluetooth.find_service(address=target) if len(services) <= 0: print( 'Running inquiry scan') services = inquire(target) socks = [] for svc in services: try: socks.append( svc ) except BluetoothError as e: print('Couldn\'t connect: ',e) if len(services) > 0: return remove_duplicate_services(socks) else: raise RuntimeError('Could not lookup '+target)
Example #5
Source File: __init__.py From platypush with MIT License | 5 votes |
def find_service(self, name: str = None, addr: str = None, uuid: str = None) -> BluetoothLookupServiceResponse: """ Look up for a service published by a nearby bluetooth device. If all the parameters are null then all the published services on the nearby devices will be returned. See `:class:platypush.message.response.bluetoothBluetoothLookupServiceResponse` for response structure reference. :param name: Service name :param addr: Service/device address :param uuid: Service UUID """ import bluetooth from bluetooth import find_service services = find_service(name=name, address=addr, uuid=uuid) self._port_and_protocol_by_addr_and_srv_uuid.update({ (srv['host'], srv['service-id']): (srv['port'], getattr(bluetooth, srv['protocol'])) for srv in services if srv.get('service-id') }) self._port_and_protocol_by_addr_and_srv_name.update({ (srv['host'], srv['name']): (srv['port'], getattr(bluetooth, srv['protocol'])) for srv in services if srv.get('name') }) return BluetoothLookupServiceResponse(services)
Example #6
Source File: __init__.py From platypush with MIT License | 5 votes |
def _get_addr_port_protocol(self, protocol=None, device: str = None, port: int = None, service_uuid: str = None, service_name: str = None) -> tuple: import bluetooth addr = self._get_device_addr(device) if device else None if service_uuid or service_name: if addr: if service_uuid: (port, protocol) = self._port_and_protocol_by_addr_and_srv_uuid[(addr, service_uuid)] \ if (addr, service_uuid) in self._port_and_protocol_by_addr_and_srv_uuid else \ (None, None) else: (port, protocol) = self._port_and_protocol_by_addr_and_srv_name[(addr, service_name)] \ if (addr, service_name) in self._port_and_protocol_by_addr_and_srv_name else \ (None, None) if not (addr and port): self.logger.info('Discovering devices, service_name={name}, uuid={uuid}, address={addr}'.format( name=service_name, uuid=service_uuid, addr=addr)) services = [ srv for srv in self.find_service().services if (service_name is None or srv.get('name') == service_name) and (addr is None or srv.get('host') == addr) and (service_uuid is None or srv.get('service-id') == service_uuid) ] if not services: raise RuntimeError('No such service: name={name} uuid={uuid} address={addr}'.format( name=service_name, uuid=service_uuid, addr=addr)) service = services[0] addr = service['host'] port = service['port'] protocol = getattr(bluetooth, service['protocol']) elif protocol: if isinstance(protocol, str): protocol = getattr(bluetooth, protocol) else: raise RuntimeError('No service name/UUID nor bluetooth protocol (RFCOMM/L2CAP) specified') if not (addr and port): raise RuntimeError('No valid device name/address, port, service name or UUID specified') return addr, port, protocol
Example #7
Source File: __init__.py From platypush with MIT License | 5 votes |
def connect(self, protocol=None, device: str = None, port: int = None, service_uuid: str = None, service_name: str = None): """ Connect to a bluetooth device. You can query the advertised services through ``find_service``. :param protocol: Supported values: either 'RFCOMM'/'L2CAP' (str) or bluetooth.RFCOMM/bluetooth.L2CAP int constants (int) :param device: Device address or name :param port: Port number :param service_uuid: Service UUID :param service_name: Service name """ from bluetooth import BluetoothSocket addr, port, protocol = self._get_addr_port_protocol(protocol=protocol, device=device, port=port, service_uuid=service_uuid, service_name=service_name) sock = self._get_sock(protocol=protocol, device=addr, port=port) if sock: self.close(device=addr, port=port) sock = BluetoothSocket(protocol) self.logger.info('Opening connection to device {} on port {}'.format(addr, port)) sock.connect((addr, port)) self.logger.info('Connected to device {} on port {}'.format(addr, port)) self._socks[(addr, port)] = sock
Example #8
Source File: message_process.py From miaomiaoji-tool with MIT License | 5 votes |
def scanservices(self): logging.info("Searching for services...") service_matches = find_service(uuid=self.uuid, address=self.address) valid_service = filter( lambda s: 'protocol' in s and 'name' in s and s['protocol'] == 'RFCOMM' and s['name'] == 'SerialPort', service_matches ) if len(valid_service) == 0: logging.error("Cannot find valid services on device with MAC %s." % self.address) return False logging.info("Found a valid service on target device.") self.service = valid_service[0] return True
Example #9
Source File: bluetooth.py From peach with Mozilla Public License 2.0 | 5 votes |
def enumerate_services(device): print("Find services on device: %s" % device) if usingBluetooth: services = bluetooth.find_service(bdaddr=device) # name ? if usingLightBlue: services = lightblue.findservices(device) print(services) return services
Example #10
Source File: sdpservices.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def run(self): print_info("Searching services...") bmac = self.args["bmac"] # User input is String (just in case) if str(bmac) == "None": print_info("This process can take time, patience") bmac = None services = find_service(address=bmac) if len(services) > 0: print_ok(f"Found {len(services)} services") print("") self._show_services(services) else: print_info("No services found")