Get Remote IP@

When your server is behind any proxies or load balancers, the remote IP@ gets masked. In such scenarios, the server variable “REMOTE_ADDR” may not provide the correct client IP@. The only way to get remote addresses is to check if the proxies rewrite the request headers which most of them does.

You can look through all HTTP request headers and try to find any “X_” or “HTTP_X” type value to get the desired IP@.

Some of HTTP request headers you can scan (in sequence) are given below:

  1. HTTP_X_CLIENTIP
  2. HTTP_CLIENT_IP
  3. HTTP_X_FORWARDED_FOR
  4. HTTP_X_FORWARDED
  5. HTTP_VIA
  6. HTTP_FORWARDED_FOR
  7. HTTP_FORWARDED
  8. REMOTE_ADDR

Sample C# implementation: