blob: a8d56a6fe0b8492d9a44033f826fe7be10d83ec1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
from flask import Flask, request
from os import environ
app = Flask(__name__)
TEMPLATE = '''
/----------------------------------------\\
| {ip:39}|
| |
| Created by Yuval Adam |
| https://github.com/yuvadm/ipcli.app |
| Comments welcome at hello@ipcli.app |
\\----------------------------------------/
'''
def get_ip(request):
if 'PROD' in environ:
# Heroku routing layers masks the original IP, fetch it from the custom header
# And make sure we just take the first IP in case other proxies were in the way
ips = request.headers.get('X-Forwarded-For')
return ips.split(',')[0]
else:
return request.remote_addr
@app.route('/')
def index():
ip = get_ip(request)
return TEMPLATE.format(ip=ip)
|