How can I get the IP of a client device connected through terminal services?

戏子无情 提交于 2019-12-11 10:14:39

问题


Problem

I need to get the client IP of a user connected through RDP/TS from an ASP site.

Sample data

  • The server hosting the site is at 10.1.0.1.
  • The user's machine is connected to a terminal server whose IP is 10.2.0.1.
  • The user is at a physical client whose IP is 10.3.0.1.

Attempted solutions

I have tried pulling the data from headers.

  • Request.ServerVariables["REMOTE_HOST"] 10.2.0.1
  • Request.ServerVariables["HTTP_X_FORWARDED_FOR"] [blank]
  • Request.ServerVariables["REMOTE_ADDR"] 10.2.0.1
  • Request.UserHostAddress 10.2.0.1

I also tried these methods.

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 + "<br />";
  }
  return ips;
}

Returns 10.2.0.1.

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;
}

Returns 10.1.0.1.

Question

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?

来源:https://stackoverflow.com/questions/56637062/how-can-i-get-the-ip-of-a-client-device-connected-through-terminal-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!