问题
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.1Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
[blank]Request.ServerVariables["REMOTE_ADDR"]
10.2.0.1Request.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