Skip to content

Instantly share code, notes, and snippets.

@aluminiumgeek
Last active January 4, 2016 07:59
Show Gist options
  • Save aluminiumgeek/8592079 to your computer and use it in GitHub Desktop.
Save aluminiumgeek/8592079 to your computer and use it in GitHub Desktop.
Tornado Client IP detection for production and development environments
def get_ip(request):
"""
Возвращает ip из HTTP-заголовков. Если там его нет, возвращает значение
атрибута remote_ip
@param request: экземпляр HTTPRequest
@return: строка, содержащая ip клиента
"""
if 'X-Real-Ip' in request.headers:
ip = request.headers['X-Real-Ip']
else:
ip = request.remote_ip
return ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment