Skip to content

Instantly share code, notes, and snippets.

@pocketkk
Created November 16, 2013 22:52
Show Gist options
  • Save pocketkk/7506466 to your computer and use it in GitHub Desktop.
Save pocketkk/7506466 to your computer and use it in GitHub Desktop.
Local IP Address
#!/usr/bin/env ruby
require 'socket'
require "/home/pi/projects/lcd/lcd"
def local_ip(target)
# turn off reverse DNS resolution
bdns, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true
UDPSocket.open do |s|
s.connect target, 8000
s.addr.last
end
ensure
# restore DNS resolution
Socket.do_not_reverse_lookup = bdns
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment