Hello,
I have Rails 2.3.8, Ruby 1.8.7, Mongrel Web Server and MySQL database.
I need to find the IP address but I am facing problems. I am in the development mode.
I googled and found code, that its simple to get the IP address using request.remote_ip
but, I am getting the output only as 127.0.0.1
In the controller, I have
def index
@title = "Index Page"
@client_ip = request.remote_ip
@remote_ip = request.env["HTTP_X_FORWARDED_FOR"]
@my_ip = request.env["HTTP_X_FORWARDED_FOR"] || request.remote_addr
@ip_addr = request.env['REMOTE_ADDR']
end
In the view, I have this code
Your IP address is <%= @client_ip %> <br/>
AG IP address is <%= @remote_ip %> <br/>
My Personal IP address is <%= @my_ip %> <br/>
IP address is <%= @ip_addr %>
The output, in the web browser I am getting is
Your IP address is 127.0.0.1
AG IP address is
My Personal IP address is 127.0.0.1
IP address is 127.0.0.1
I know I am getting 127.0.0.1 because I am developing on the local machine.. but is there a way to get the real ip-address even if I am on the local machine?
Looking forward for your help and support.
Thanks