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.

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

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

On Sun, Oct 7, 2012 at 12:20 PM, ajay paswan [email protected]
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/.

You can can use the system method, as in…

system “”

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