# Capturing an IP Address

**URL:** <https://www.ruby-forum.com/t/capturing-an-ip-address/117276>\
**Category:** Rails\
**Created:** [October 15, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276 "2007-10-15T15:40:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 3:40pm UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276/1 "2007-10-15T15:40:12Z")

</div>

How do I capture an IP address and send it into a database field?  
There is no DRY convention for this like a password\_confirmation for  
example right?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 4:15pm UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276/2 "2007-10-15T16:15:57Z")

</div>

On Mon, 2007-10-15 at 13:38 +0000, removed\_email\_address@domain.invalid wrote:

> How do I capture an IP address and send it into a database field?  
> There is no DRY convention for this like a password\_confirmation for  
> example right?

model.ip\_address = request.remote\_ip

–  
Tore D.  
removed\_email\_address@domain.invalid  
Trondheim, NO  
[http://tore.darell.no/](http://tore.darell.no/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 15, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276/3 "2007-10-15T17:33:21Z")

</div>

Thanks, it works.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 24, 2009, 10:43am UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276/4 "2009-02-24T10:43:02Z")

</div>

Tore D. wrote:

> On Mon, 2007-10-15 at 13:38 +0000, removed\_email\_address@domain.invalid wrote:
> 
> > How do I capture an IP address and send it into a database field?  
> > There is no DRY convention for this like a password\_confirmation for  
> > example right?
> 
> model.ip\_address = request.remote\_ip
> 
> –  
> Tore D.  
> removed\_email\_address@domain.invalid  
> Trondheim, NO  
> [http://tore.darell.no/](http://tore.darell.no/)

i used

request.remote\_ip

but i am getting different ip address at local and at server… its  
strange…  
can any one give any idea…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 24, 2009, 12:24pm UTC](https://www.ruby-forum.com/t/capturing-an-ip-address/117276/5 "2009-02-24T12:24:44Z")

</div>

on your local machine it might give you the ip of your lan/intranet  
(from your router). on your server you get the external one given to  
you by your isp.
