Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get client's IP address in Sinatra?

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 '/' do     "Your IP address is #{....}" end 
like image 915
dbr Avatar asked Aug 23 '09 19:08

dbr


People also ask

What is the IP address of the client?

Client IP addresses describe only the computer being used, not the user. If multiple users share the same computer, they will be indistinguishable. Many Internet service providers dynamically assign IP addresses to users when they log in.


1 Answers

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 
like image 110
meagar Avatar answered Sep 20 '22 02:09

meagar