Skip to content

Instantly share code, notes, and snippets.

@rickhull
Created March 25, 2011 16:20
Show Gist options
  • Save rickhull/887120 to your computer and use it in GitHub Desktop.
Save rickhull/887120 to your computer and use it in GitHub Desktop.
def self.local_ip_address
require 'socket'
# turn off reverse DNS resolution temporarily
orig, Socket.do_not_reverse_lookup =
Socket.do_not_reverse_lookup, true
# does not actually hit network
UDPSocket.open do |s|
s.connect '64.233.187.99', 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