在Sinatra中获取客户的IP地址?

问题描述:

这是一个非常简单的问题,但我在任何地方都找不到任何提及..

This is a really simple question, but I cannot find any mention of this, anywhere..

如何从Sinatra中获取客户的IP地址?

How do I get the client's IP address from in Sinatra?

get '/' do
    "Your IP address is #{....}"
end

Sinatra提供了

Sinatra provides a request object, which is the interface to the client request data that you should be using.

使用request.ip是查找客户端IP地址的首选方法:

Using request.ip is the preferred method to find the client's IP address:

get '/' do
  "Your IP address is #{request.ip}"
end