Created
December 21, 2019 01:06
-
-
Save TobiX/1e7db748e732a498ce5f1270659420c4 to your computer and use it in GitHub Desktop.
Remote Address API server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
from werkzeug.wrappers import Request, Response | |
from werkzeug.middleware.proxy_fix import ProxyFix | |
@Request.application | |
def application(request): | |
data = {'addr': request.environ['REMOTE_ADDR']} | |
text = json.dumps(data, sort_keys=True) | |
response = Response(text) | |
response.headers['content-type'] = 'application/json' | |
response.headers['content-length'] = len(response.data) | |
return response | |
if __name__ == '__main__': | |
from werkzeug.serving import run_simple | |
proxyapp = ProxyFix(application, x_for=1, x_host=1) | |
run_simple('localhost', 4000, proxyapp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment