Committing get_ip()

selenium-screenshot-testing
CodeKevin 2016-02-06 15:08:39 -05:00
parent 85e8a9d271
commit c336ad6fd1
1 changed files with 11 additions and 0 deletions

View File

@ -7,6 +7,8 @@ from flask import current_app as app, g, request, redirect, url_for, session, re
from flask.ext.mail import Message
from socket import inet_aton, inet_ntoa
from struct import unpack, pack
from sqlalchemy.engine.url import make_url
from sqlalchemy import create_engine
import time
import datetime
@ -204,6 +206,15 @@ def unix_time_millis(dt):
return unix_time(dt) * 1000
def get_ip():
trusted_proxies = {'127.0.0.1'} # define your own set
route = request.access_route + [request.remote_addr]
remote_addr = next((addr for addr in reversed(route)
if addr not in trusted_proxies), request.remote_addr)
return remote_addr
def long2ip(ip_int):
return inet_ntoa(pack('!I', ip_int))