Skip to content

Instantly share code, notes, and snippets.

@TobiX
Created December 21, 2019 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TobiX/1e7db748e732a498ce5f1270659420c4 to your computer and use it in GitHub Desktop.
Save TobiX/1e7db748e732a498ce5f1270659420c4 to your computer and use it in GitHub Desktop.
Remote Address API server
#!/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