Module: Vagrant::Butter::Helpers

Defined in:
lib/vagrant/butter/helpers.rb

Instance Method Summary collapse

Instance Method Details

#local_ipString

Returns the local IP address of the host running the vagrant VMs.

Thanks to: github.com/jedi4ever/veewee/blob/c75a5b175c5b8ac7e5aa3341e93493923d0c7af0/lib/veewee/session.rb#L622

Returns:

  • (String)

    the local IP address



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant/butter/helpers.rb', line 15

def local_ip
  @local_ip ||= begin
    # turn off reverse DNS resolution temporarily
    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
end