Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want is in the wsgi <a href="http://www.python.org/dev/peps/pep-0333/#environ-variables" rel="nofollow noreferrer">environ</a>, specifically <code>environ['REMOTE_ADDR']</code>. </p> <p>However, if there is a proxy involved, then <code>REMOTE_ADDR</code> will be the address of the proxy, and the client address will be included (most likely) in <code>HTTP_X_FORWARDED_FOR</code>. </p> <p>Here's a function that should do what you want, for most cases (all credit to <a href="https://stackoverflow.com/questions/4581789/how-do-i-get-user-ip-address-in-django/5976065#5976065">Sævar</a>):</p> <pre><code>def get_client_address(environ): try: return environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip() except KeyError: return environ['REMOTE_ADDR'] </code></pre> <hr> <p>You can easily see what is included in the wsgi environ by writing a simple wsgi app and pointing a browser at it, for example:</p> <pre><code>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) </code></pre> <hr> <p>And combining the two ...</p> <pre><code>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) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload