在Rails中获得实际的远程IP? [英] Get Actual Remote IP in Rails?

查看:47
本文介绍了在Rails中获得实际的远程IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Rails(2.3.8)应用程序.我需要存储实际客户端的远程IP地址.

I'm developing rails(2.3.8) application. I need to store actual client's remote IP address.

request.remote_ip仅返回127.0.0.1

,但是我需要存储实际的远程IP,例如93.43.56.77.有红宝石宝石可用吗?或如何获得?

but I need to store actual remote IP such as 93.43.56.77. Any ruby gems is available? or how do get that?

推荐答案

尝试一下:

request.env['REMOTE_ADDR']

如果您的请求来自开发机器,而开发机器是服务器所在的位置,则可能会得到127.0.0.1.但是,如果请求来自另一台计算机,则它将是远程计算机的IP.但是,在各种情况下,这可能不是机器的真实IP(代理后的机器,使用tor或其他工具等将其隐藏).

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. But if the request is coming from another machine, this will be the IP the remote machine. 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 e.t.c.).

这篇关于在Rails中获得实际的远程IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆