def get_client_ip(request):
ip=None
x_forwarded = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded:
ip=x_forwarded.split(',')[0]
elif not ip:
ip = request.META.get('REMOTE_ADDR')
else:
ip = request.META.get('HTTP_X_REAL_IP')
return ip