# Obtaining ip address of client socket in ruby

**URL:** <https://www.ruby-forum.com/t/obtaining-ip-address-of-client-socket-in-ruby/121148>\
**Category:** Ruby\
**Created:** [November 24, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/obtaining-ip-address-of-client-socket-in-ruby/121148 "2007-11-24T16:39:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [November 24, 2007, 4:39pm UTC](https://www.ruby-forum.com/t/obtaining-ip-address-of-client-socket-in-ruby/121148/1 "2007-11-24T16:39:03Z")

</div>

How can I obtain the ip address of the originating (client) socket ,  
in a server/client socket ruby program?

What ruby library is fitted with a class/ method to do this?  
How can it be done using ruby?

I would appreciate some sample code.

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [November 24, 2007, 5:01pm UTC](https://www.ruby-forum.com/t/obtaining-ip-address-of-client-socket-in-ruby/121148/2 "2007-11-24T17:01:55Z")

</div>

2007/11/24, Victor R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> How can I obtain the ip address of the originating (client) socket ,  
> in a server/client socket ruby program?
> 
> What ruby library is fitted with a class/ method to do this?  
> How can it be done using ruby?
> 
> I would appreciate some sample code.

[http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib\_network.html](http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_network.html)

robert

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [November 24, 2007, 6:35pm UTC](https://www.ruby-forum.com/t/obtaining-ip-address-of-client-socket-in-ruby/121148/3 "2007-11-24T18:35:40Z")

</div>

From: “Robert K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 2007/11/24, Victor R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > How can I obtain the ip address of the originating (client) socket ,  
> > in a server/client socket ruby program?
> > 
> > What ruby library is fitted with a class/ method to do this?  
> > How can it be done using ruby?
> > 
> > I would appreciate some sample code.
> 
> [Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_network.html)

sock\_domain, remote\_port, remote\_hostname, remote\_ip = socket.peeraddr

# note: sock\_domain is the address family, e.g. “AF\_INET”

Regards,

Bill
