Exemple #1
0
    def sync_one_mapping(self, local_port, protocol):

        self.logger.info('Sync one mapping: {0}'.format(local_port))
        port_to_try = local_port
        lower_limit = 10000
        found_external_port = None
        retries = 10
        for i in range(1, retries):
            self.logger.info('Trying {0}'.format(port_to_try))
            external_port = self.port_mapper.add_mapping(
                local_port, port_to_try, protocol)
            if not is_web_port(local_port):
                found_external_port = external_port
                break
            if self.port_prober.probe_port(external_port,
                                           port_to_protocol(local_port)):
                found_external_port = external_port
                break
            self.port_mapper.remove_mapping(local_port, external_port,
                                            protocol)

            if port_to_try == local_port:
                port_to_try = lower_limit
            else:
                port_to_try = external_port + 1

        if not found_external_port:
            raise Exception(
                'Unable to add mapping, tried {0} times'.format(retries))

        mapping = Port(local_port, found_external_port, protocol)
        self.port_config.add_or_update(mapping)
Exemple #2
0
 def add_mapping(self, local_port, external_port, protocol):
     self.logger.warn(
         'adding port mapping is not available in manual mode {0}:{1}'.
         format(self.manual_public_ip, self.manual_public_web_port))
     if is_web_port(local_port):
         return self.manual_public_web_port
     else:
         return external_port
Exemple #3
0
    def sync_new_port(self, local_port, protocol):

        self.logger.info('Sync one mapping: {0}'.format(local_port))
        port_to_try = local_port
        lower_limit = 10000
        found_external_port = None
        retries = 10
        message = 'no message from dns service'
        for i in range(1, retries):
            self.logger.info('Trying {0}'.format(port_to_try))

            external_port = self.port_mapper.add_mapping(
                local_port, port_to_try, protocol)
            if not is_web_port(local_port):
                self.logger.info('not probing non http(s) ports')
                found_external_port = external_port
                break

            external_ip = self.port_mapper.external_ip()
            if external_ip is not None:
                ip_version = IP(external_ip).version()
                if ip_version == 6:
                    self.logger.info('probing of IPv6 is not supported yet')
                    found_external_port = external_port
                    break

            probe_success, message = self.port_prober.probe_port(
                external_port, port_to_protocol(local_port), external_ip)
            if probe_success:
                found_external_port = external_port
                break
            self.port_mapper.remove_mapping(local_port, external_port,
                                            protocol)

            if port_to_try == local_port:
                port_to_try = lower_limit
            else:
                self.logger.info('external port: {0}'.format(external_port))
                port_to_try = external_port + 1

        if not found_external_port:
            raise Exception('Unable to verify open ports, {0}'.format(message))

        mapping = Port(local_port, found_external_port, protocol)
        self.port_config.add_or_update(mapping)
        return mapping
Exemple #4
0
    def sync_one_mapping(self, local_port, protocol):

        self.logger.info('Sync one mapping: {0}'.format(local_port))
        port_to_try = local_port
        lower_limit = 10000
        found_external_port = None
        retries = 10
        for i in range(1, retries):
            self.logger.info('Trying {0}'.format(port_to_try))

            external_port = self.port_mapper.add_mapping(
                local_port, port_to_try, protocol)
            if not is_web_port(local_port):
                self.logger.info('not probing non http(s) ports')
                found_external_port = external_port
                break

            ip_version = IP(self.port_mapper.external_ip()).version()
            if ip_version == 6:
                self.logger.info('probing of IPv6 is not supported yet')
                found_external_port = external_port
                break

            if self.port_prober.probe_port(external_port,
                                           port_to_protocol(local_port)):
                found_external_port = external_port
                break
            self.port_mapper.remove_mapping(local_port, external_port,
                                            protocol)

            if port_to_try == local_port:
                port_to_try = lower_limit
            else:
                self.logger.info('external port: {0}'.format(external_port))
                port_to_try = external_port + 1

        if not found_external_port:
            raise Exception(
                'Unable to verify open ports, tried {0} times'.format(retries))

        mapping = Port(local_port, found_external_port, protocol)
        self.port_config.add_or_update(mapping)
        return mapping