# How to get the Client IP address with webrick

**URL:** <https://www.ruby-forum.com/t/how-to-get-the-client-ip-address-with-webrick/114206>\
**Category:** Ruby\
**Created:** [September 9, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/how-to-get-the-client-ip-address-with-webrick/114206 "2007-09-09T21:23:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 9, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/how-to-get-the-client-ip-address-with-webrick/114206/1 "2007-09-09T21:23:21Z")

</div>

I need to ensure that the user who has sent the request is the localhost  
… what’s the best way to do this?

---

<div class="post-metadata">

**Author:** ![ssyed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7ab992/32.png) [@ssyed](https://www.ruby-forum.com/u/ssyed)\
**Post date:** [September 10, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/how-to-get-the-client-ip-address-with-webrick/114206/2 "2007-09-10T15:30:39Z")

</div>

Sal Syed wrote:

> I need to ensure that the user who has sent the request is the localhost  
> … what’s the best way to do this?

… i don’t know how to do this via webrick, but u find out the  
remote\_ip that required the request in the app code simply so:  
request.remote\_ip

so u could do something like

class SomeController

before\_filter :block\_localhosts

def action1  
end

def action2  
end

def block\_localhosts  
if request.remote\_ip=~/127.0.0.1/  
return false  
end  
end

end

in the example above, all requests coming from 127.0.0.1 won’t be  
rendered.  
hth 🙂
