I am doing Rails development in Ubuntu 12.04LTS OS.
I want to capture my local IP address in a file, not the loopback 127.0.0.1, the one which I get using ifc
Write below method
def self.local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open do |s|
s.connect '64.233.187.99', 1
s.addr.last
end
ensure
Socket.do_not_reverse_lookup = orig
end
and then call local_ip method, you will get ip address of your machine.
Eg: ip_address= local_ip