Know my IP in LAN

Hi how can I know my IP through which two computers communicate in LAN?
Like in socket, I wanna send my IP to the target machine.

···

--
Posted via http://www.ruby-forum.com/.

Use gethostbyaddr. Toss it in a string and send it along.

···

On Sun, Oct 7, 2012 at 10:20 AM, ajay paswan <lists@ruby-forum.com> wrote:

Hi how can I know my IP through which two computers communicate in LAN?
Like in socket, I wanna send my IP to the target machine.

--
Posted via http://www.ruby-forum.com/\.

--

vizualize.me/cliffrosson

You can can use the system method, as in...

system "<whatever command you would use to check your ipaddress on your OS>"

But, you can easily do it without forking another shell.

Somebody else wrote this...

require 'socket'
def local_ip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup,
true # turn off reverse DNS resolution temporarily
  UDPSocket.open do |s|
    s.connect '64.233.187.99', 1
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end

p local_ip

It checks the ip it would use to route to a random address without out
sending any packets.
Todd

···

On Sun, Oct 7, 2012 at 12:20 PM, ajay paswan <lists@ruby-forum.com> wrote:

Hi how can I know my IP through which two computers communicate in LAN?
Like in socket, I wanna send my IP to the target machine.

--
Posted via http://www.ruby-forum.com/\.

Woops. I think ip_address_list is closer to what you want.

···

On Sun, Oct 7, 2012 at 11:13 AM, Cliff Rosson <cliff.rosson@gmail.com>wrote:

Use gethostbyaddr. Toss it in a string and send it along.

Class: Socket (Ruby 1.9.3)

On Sun, Oct 7, 2012 at 10:20 AM, ajay paswan <lists@ruby-forum.com> wrote:

Hi how can I know my IP through which two computers communicate in LAN?
Like in socket, I wanna send my IP to the target machine.

--
Posted via http://www.ruby-forum.com/\.

--
Cliff Rosson | about.me
vizualize.me/cliffrosson

--

vizualize.me/cliffrosson