Created
September 7, 2009 16:08
-
-
Save jasonmadigan/182423 to your computer and use it in GitHub Desktop.
Local IP lookup
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' | |
class GetIP | |
def self.local_ip | |
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true | |
UDPSocket.open do |s| | |
s.connect '64.233.187.99', 1 # Relax, nothing is hitting the network | |
s.addr.last | |
end | |
ensure | |
Socket.do_not_reverse_lookup = orig | |
end | |
end | |
if $0 == __FILE__ | |
puts GetIP.local_ip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment