[英]Get Actual Remote IP in Rails?
I'm developing rails(2.3.8) application. 我正在开发rails(2.3.8)应用程序。 I need to store actual client's remote IP address.
我需要存储实际客户端的远程IP地址。
request.remote_ip
returns only 127.0.0.1
request.remote_ip
仅返回127.0.0.1
but I need to store actual remote IP such as 93.43.56.77
. 但我需要存储实际的远程IP,如
93.43.56.77
。 Any ruby gems is available? 有红宝石可供选择吗? or how do get that?
或者怎么做到的?
Try this: 尝试这个:
request.env['REMOTE_ADDR']
If your request is coming from your development machine and the development machine is where your server is, probably you will get 127.0.0.1
. 如果您的请求来自您的开发机器并且开发机器是您的服务器所在的位置,那么您可能会得到
127.0.0.1
。 But if the request is coming from another machine, this will be the IP the remote machine. 但是如果请求来自另一台机器,这将是远程机器的IP。 However, under various conditions this may not be the real IP of the machine (machine behind proxy, using tor or other tool to hide it etc).
但是,在各种条件下,这可能不是机器的真正IP(代理机器,使用tor或其他工具隐藏它等)。
Your computer essentially has two network interfaces. 您的计算机本质上有两个网络接口。
You will not get the application to show '93.43.56.77' unless the connection is running over that connection, which means it will need to be on a different computer. 除非连接在该连接上运行,否则您不会让应用程序显示'93 .43.56.77',这意味着它需要位于不同的计算机上。
If you are so concerned about it, you can easily push it up to Heroku where it should work as you expect. 如果你如此关注它,你可以轻松地将它推到Heroku,它应该按照你的预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.