4

Im doing a app in which i need to find the clients ip address. I used request.remote_ip for getting the client's ip and it fetched the public ip address of the client for http request. When it is a https request request.remote_ip fetched different ip like 10.114.237.132 (i think this is a private ip) other than the public ip address.I also tried request.env['REMOTE_ADDR'] My question is how to find the remote ip of a client for https request.

UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92
  • @Jesse That is private address `10.114.237.132` is in range 10.0.0.0 - 10.255.255.255 which is private range. – Haris Krajina May 16 '13 at 12:30
  • I think its load balancers ip address. I am not sure. – Bharath kumar May 16 '13 at 12:35
  • Dolphin is correct, that is a private IP address. Bharath, it may be a load balancer as you mention, or any internal server "receiving" the connection first. There is always the possibility of the IP address being spoofed. – Jesse May 16 '13 at 12:39

1 Answers1

0

If this the laod balancer's IP, try to figure out if it can provide you an HTTP header to get the client IP. If you can configure it or if it's already proving it, you can check the HTTP Headers using this method Request.headers() method.

The header you should looking for is X-Forwarded-For.

Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
  • I used env['HTTP_X_FORWARDED_FOR'] in middleware for getting the client ip and the proxy ip but it didnt returned anyhting. – Bharath kumar May 16 '13 at 14:09
  • Paulo Http header will have REMOTE_ADDR right? I think it will also give the proxy ip . – Bharath kumar May 16 '13 at 14:11
  • That will always depend if the load balancer fills this headers. Like in HTTP Proxies, it depends if the proxy supports or is configured to fill the header. You'll need to check in your load balancer documentation. – Paulo Fidalgo May 16 '13 at 14:48