Get client's IP address in Sinatra?

前端 未结 2 1368
小蘑菇
小蘑菇 2020-12-28 12:48

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

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

get \'/\'          


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 13:12

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

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

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

提交回复
热议问题