get the client IP address bassed on a HTTPRequest

def get_user_ip(self, request):
        """
        get the client IP address bassed on a HTTPRequest
        """

        client_ip_address = None

        # searching the IP address
        for key in self.configuration.network.ip_meta_precedence_order:

            ip_meta_value = request.META.get(key, '').strip()

            if ip_meta_value != '':
                ips = [ip.strip().lower() for ip in ip_meta_value.split(',')]

                for ip_str in ips:

                    if ip_str and is_valid_ip(ip_str):

                        if not ip_str.startswith(self.configuration.network.non_public_ip_prefixes):
                            return ip_str

                        elif not self.configuration.network.real_ip_only:
                            loopback = ('127.0.0.1', '::1')

                            if client_ip_address is None:
                                client_ip_address = ip_str

                            elif client_ip_address in loopback and ip_str not in loopback:
                                client_ip_address = ip_str

        if client_ip_address is None and settings.DEBUG:
            raise DobermanImproperlyConfigured(
                "Unknown IP, maybe you are working on localhost/development, "
                "so please set in your setting: DOBERMAN_REAL_IP_ONLY=False"
            )

        return client_ip_address