Skip to content

Instantly share code, notes, and snippets.

@larsch
Created September 9, 2010 13:12
Show Gist options
  • Select an option

  • Save larsch/571837 to your computer and use it in GitHub Desktop.

Select an option

Save larsch/571837 to your computer and use it in GitHub Desktop.
Detect the hosts IP address
require 'socket'
def local_ip
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open do |s|
s.connect '8.8.8.8', 1
s.addr.last
end
ensure
Socket.do_not_reverse_lookup = orig
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment