title: Get original IP when request is made via proxies
body: <p>I am writing a little Python script that checks and displays incoming IP addresses. Getting an IP address directly was achieved by simply using the following:</p>
  
  <pre><code>remote_addr2 = os.environ.get('REMOTE_ADDR')
  </code></pre>
  
  <p>This displays the correct IP address making the request. The challenge I am facing is to detect the original IP if the request is made using a proxy. From <a href="http://twigstechtips.blogspot.in/2011/04/note-http-header-httpxforwardedfor-will.html" rel="nofollow noreferrer">here</a>, I gather I must use <code>HTTP_X_FORWARDED_FOR</code> and so I tried to assign that to a variable and display it, like so:</p>
  
  <pre><code>remote_addr1 = os.environ.get('HTTP_X_FORWARDED_FOR')
  </code></pre>
  
  <p>The output for this is always <code>None</code>. I see a similar question answered for where the <a href="https://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php?rq=1">OP was using PHP</a>. I think what I am trying to achieve in the second line is similar, but every proxy that I've tested (Anonymouse, HideMyAss, FilterByPass), gives me 'None' as an output. </p>
  
  <p>This is the full program (rudimentary and I haven't implemented validation yet):</p>
  
  <pre><code>#!/usr/bin/python
  
  import os
  import cgi
  
  print "Content-type:text/html\r\n\r\n"
  print '&lt;html&gt;'
  print '&lt;head&gt;'
  print '&lt;title&gt;WHOIS - TESTs&lt;/title&gt;'
  print '&lt;/head&gt;'
  
  remote_addr1 = os.environ.get('HTTP_X_FORWARDED_FOR')
  remote_addr2 = os.environ.get('REMOTE_ADDR')
  
  print '&lt;body&gt;'
  print remote_addr1
  print remote_addr2
  #print cgi.escape(os.environ["REMOTE_ADDR"])
  print '&lt;/body&gt;'
  print '&lt;/html&gt;'
  </code></pre>
  
  <p>Sample output:</p>
  
  <p><img src="https://i.stack.imgur.com/YSpZd.png" alt="output"></p>
  
  <p>Where am I making a mistake? Thanks in advance.</p>