title: How can I get the IP of a client device connected through terminal services?
body: <h1>Problem</h1>
  
  <p>I need to get the client IP of a user connected through RDP/TS from an ASP site. </p>
  
  <h1>Sample data</h1>
  
  <ul>
  <li>The server hosting the site is at 10.1.0.1.</li>
  <li>The user's machine is connected to a terminal server whose IP is 10.2.0.1.</li>
  <li>The user is at a physical client whose IP is 10.3.0.1.</li>
  </ul>
  
  <h1>Attempted solutions</h1>
  
  <p>I have tried pulling the data from headers.</p>
  
  <ul>
  <li><code>Request.ServerVariables["REMOTE_HOST"]</code> 10.2.0.1</li>
  <li><code>Request.ServerVariables["HTTP_X_FORWARDED_FOR"]</code> [blank]</li>
  <li><code>Request.ServerVariables["REMOTE_ADDR"]</code> 10.2.0.1</li>
  <li><code>Request.UserHostAddress</code> 10.2.0.1</li>
  </ul>
  
  <p>I also tried these methods.</p>
  
  <pre><code>public static string getIP()
  {
    string ips = string.Empty;
    string hostName = HttpContext.Current.Request.UserHostAddress.ToString();
    IPAddress[] ipAddresses = Dns.GetHostAddresses(hostName);
    foreach (IPAddress ipAddress in ipAddresses)
    {
      ips += ipAddress + "&lt;br /&gt;";
    }
    return ips;
  }
  </code></pre>
  
  <p>Returns 10.2.0.1.</p>
  
  <pre><code>public static string GetIPAddress()
  {
    string ipAddress = "";
    string Hostname = Environment.MachineName;
    IPHostEntry Host = Dns.GetHostEntry(Hostname);
    foreach (IPAddress IP in Host.AddressList)
    {
      if (IP.AddressFamily == AddressFamily.InterNetwork)
      {
        ipAddress= Convert.ToString(IP);
      }
    }
    return ipAddress;
  }
  </code></pre>
  
  <p>Returns 10.1.0.1.</p>
  
  <h1>Question</h1>
  
  <p>Is it possible to get 10.3.0.1 returned since there is an extra hop from the user's physical client through the TS to the web server? Is this possible with another language--e.g., PHP?</p>