0

there is such situation: i have the server my.qwe (192.168.0.1) which addresses to balancer 192.168.0.2 which throws the client on 192.168.0.3 or 192.168.0.4. I make a request from the machine 192.168.0.5. Question: how to get the ip address of my machine. Note: I used

HttpContext.Current.Request.ServerVariables["HTTP_X_COMING_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED"]
HttpContext.Current.Request.ServerVariables["HTTP_VIA"]
HttpContext.Current.Request.ServerVariables["HTTP_COMING_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED_FOR"]
HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED"]
HttpContext.Current.Request.ServerVariables["HTTP_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_PROXY_CONNECTION"]
HttpContext.Current.Request.ServerVariables["CLIENT_IP"]
HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
HttpContext.Current.Request.ServerVariables["FORWARDED"]

gives out either the empty string or the ip address of the balancer 192.168.0.2, what should I do ???

Oleh
  • 1
  • 1
  • Why don't you implement some code that dumps out all the headers on the request, and then you can easily see which one contains the client's real IP? – mason Aug 30 '18 at 20:42

1 Answers1

-1

You can use either:

Request.UserHostAddress

Or:

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]

Both should work. You can find more info about that here:

What is the difference between Request.UserHostAddress and Request.ServerVariables["REMOTE_ADDR"].ToString()

Matt
  • 1,245
  • 2
  • 17
  • 32