Created
November 16, 2013 22:52
-
-
Save pocketkk/7506466 to your computer and use it in GitHub Desktop.
Local IP Address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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