What do you want in wsgi environ , in particular environ['REMOTE_ADDR'] .
However, if there is a connected proxy, then REMOTE_ADDR will be the proxy address, and the client address will be included (most likely) in HTTP_X_FORWARDED_FOR .
Here is a function that should do what you want in most cases (all Sævar loans):
def get_client_address(environ): try: return environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip() except KeyError: return environ['REMOTE_ADDR']
You can easily see what is included in the wsgi environment by writing a simple wsgi application and pointing the browser to it, for example:
from eventlet import wsgi import eventlet from pprint import pformat def show_env(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return ['%s\r\n' % pformat(env)] wsgi.server(eventlet.listen(('', 8090)), show_env)
And the union of the two ...
from eventlet import wsgi import eventlet from pprint import pformat def get_client_address(environ): try: return environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip() except KeyError: return environ['REMOTE_ADDR'] def show_env(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return ['%s\r\n\r\nClient Address: %s\r\n' % (pformat(env), get_client_address(env))] wsgi.server(eventlet.listen(('', 8090)), show_env)
Marty
source share