# How to obtain clients IP adress

**URL:** <https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351>\
**Category:** Rails\
**Created:** [June 28, 2006, 9:18am UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351 "2006-06-28T09:18:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 28, 2006, 9:18am UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/1 "2006-06-28T09:18:32Z")

</div>

Is it possible to obtain clients adress in ruby on rails?

by

TheR

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 28, 2006, 9:56am UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/2 "2006-06-28T09:56:48Z")

</div>

with request.remote\_ip?

[http://railsmanual.org/class/ActionController%3A%3AAbstractRequest/remote\_ip](http://railsmanual.org/class/ActionController%3A%3AAbstractRequest/remote_ip)

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 28, 2006, 4:28pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/3 "2006-06-28T16:28:33Z")

</div>

request.remote\_ip is, as mentioned above, what you’re looking for  
within Rails. User agent, referer, etc, can all be gained from the  
request object.

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [December 7, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/4 "2006-12-07T15:58:57Z")

</div>

hi, i was wondering is this something i would do if for example i have a  
rating system on my site and would like to allow the public to rate the  
item only once, i can log their ipaddress in a table after they rate?

so if ipaddress is in table for a rating, i do nothing or display a  
“thanks for rating” message?

thanks.

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [June 28, 2006, 2:01pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/5 "2006-06-28T14:01:56Z")

</div>

reg

Damjan R. \<d\_rems@…\> writes:

> Is it possible to obtain clients adress in ruby on rails?
> 
> by
> 
> TheR

Hi

ipaddress= request.env[‘REMOTE\_ADDR’]

you can try all all CGI environment variables

HTTP\_USER\_AGENT,HTTP\_REFERER etc

hope that helps

regards  
A.Senthil N.

[http://senthilnayagam.com](http://senthilnayagam.com)

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [December 7, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/6 "2006-12-07T17:01:55Z")

</div>

so i guess the easiest way to get around this is to maintain a  
registration table with user/pw like acts\_as\_authenticated?

Greg D. wrote:

> On 12/7/06, mixplate [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > hi, i was wondering is this something i would do if for example i have a  
> > rating system on my site and would like to allow the public to rate the  
> > item only once, i can log their ipaddress in a table after they rate?
> > 
> > so if ipaddress is in table for a rating, i do nothing or display a  
> > “thanks for rating” message?
> 
> If your app runs proxied under Apache use this:  
> request.env[‘HTTP\_X\_FORWARDED\_FOR’]
> 
> Direct requests:  
> request.env[‘REMOTE\_ADDR’]
> 
> You realize most your AOL (and other large ISPs) visitors will appear  
> to be coming from the same IP addresses right?
> 
> –  
> Greg D.  
> [http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [December 7, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/7 "2006-12-07T16:57:26Z")

</div>

On 12/7/06, mixplate [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi, i was wondering is this something i would do if for example i have a  
> rating system on my site and would like to allow the public to rate the  
> item only once, i can log their ipaddress in a table after they rate?
> 
> so if ipaddress is in table for a rating, i do nothing or display a  
> “thanks for rating” message?

If your app runs proxied under Apache use this:  
request.env[‘HTTP\_X\_FORWARDED\_FOR’]

Direct requests:  
request.env[‘REMOTE\_ADDR’]

You realize most your AOL (and other large ISPs) visitors will appear  
to be coming from the same IP addresses right?

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [December 7, 2006, 5:46pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/8 "2006-12-07T17:46:32Z")

</div>

Hi Greg,  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![ther](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/977dab/32.png) [@ther](https://www.ruby-forum.com/u/ther)\
**Post date:** [December 7, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/how-to-obtain-clients-ip-adress/96351/9 "2006-12-07T17:43:47Z")

</div>

On 12/7/06, mixplate [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> so i guess the easiest way to get around this is to maintain a  
> registration table with user/pw like acts\_as\_authenticated?

You might go ahead and store the IPs but then also take into account  
the time span since the last rating was recorded. If it’s less than  
24 hours ignore it or whatever.

That’s sorta what I do in my free image rating script:  
[http://destiney.com/php#Destiney\_rated\_images](http://destiney.com/php#Destiney_rated_images)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
