当前位置: 首页>>代码示例>>Python>>正文


Python bluetooth.find_service方法代码示例

本文整理汇总了Python中bluetooth.find_service方法的典型用法代码示例。如果您正苦于以下问题:Python bluetooth.find_service方法的具体用法?Python bluetooth.find_service怎么用?Python bluetooth.find_service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bluetooth的用法示例。


在下文中一共展示了bluetooth.find_service方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_rfcomm_port

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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)
        ) 
开发者ID:base4sistemas,项目名称:pyescpos,代码行数:18,代码来源:bt.py

示例2: safe_connect

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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) 
开发者ID:conorpp,项目名称:btproxy,代码行数:24,代码来源:mitm.py

示例3: scan

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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() 
开发者ID:fO-000,项目名称:bluescan,代码行数:24,代码来源:sdp_scan.py

示例4: connect

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:24,代码来源:dirtytooth.py

示例5: find_service

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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) 
开发者ID:BlackLight,项目名称:platypush,代码行数:28,代码来源:__init__.py

示例6: connect

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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 
开发者ID:BlackLight,项目名称:platypush,代码行数:28,代码来源:__init__.py

示例7: scanservices

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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 
开发者ID:ihciah,项目名称:miaomiaoji-tool,代码行数:15,代码来源:message_process.py

示例8: enumerate_services

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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 
开发者ID:MozillaSecurity,项目名称:peach,代码行数:13,代码来源:bluetooth.py

示例9: run

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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") 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:16,代码来源:sdpservices.py

示例10: _get_addr_port_protocol

# 需要导入模块: import bluetooth [as 别名]
# 或者: from bluetooth import find_service [as 别名]
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 
开发者ID:BlackLight,项目名称:platypush,代码行数:47,代码来源:__init__.py


注:本文中的bluetooth.find_service方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。