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 "https://stackoverflow.com/" do
"Your IP address is #{request.ip}"
end