Fix ip response
This commit is contained in:
parent
48d77068ae
commit
ca8d7c6edd
1 changed files with 10 additions and 5 deletions
15
app.py
15
app.py
|
|
@ -11,8 +11,13 @@ class GetClientIpMixin:
|
|||
for header_name in ('x-real-ip', 'x-forwarded-for'):
|
||||
candidate_ip = None
|
||||
header_value = request.headers.get(header_name)
|
||||
if not header_value:
|
||||
continue
|
||||
for ip in header_value.split(',')[::-1]:
|
||||
candidate_ip = ip_address(ip.strip())
|
||||
try:
|
||||
candidate_ip = ip_address(ip.strip())
|
||||
except ValueError:
|
||||
continue
|
||||
if candidate_ip.is_global:
|
||||
break
|
||||
if candidate_ip:
|
||||
|
|
@ -48,8 +53,8 @@ if __name__ == '__main__':
|
|||
import os
|
||||
from argparse import ArgumentParser
|
||||
|
||||
default_host = os.environ.get('APP_HOST', 'localhost')
|
||||
default_port = int(os.environ.get('APP_PORT', 8081))
|
||||
default_host = os.environ.get('APP_HOST', '0.0.0.0')
|
||||
default_port = int(os.environ.get('APP_PORT', 8080))
|
||||
default_trusted = os.environ.get('TRUSTED_PROXIES') or None
|
||||
|
||||
parser = ArgumentParser('app.py')
|
||||
|
|
@ -58,5 +63,5 @@ if __name__ == '__main__':
|
|||
parser.add_argument('--proxies', type=str, help='A list of trusted proxies, comma separated. you can use CIDRs.', default=default_trusted)
|
||||
args = parser.parse_args()
|
||||
|
||||
txip = Application(args)
|
||||
txip.run()
|
||||
zero_if = Application(args)
|
||||
zero_if.run()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue