Created
November 9, 2012 11:14
-
-
Save atog/4045198 to your computer and use it in GitHub Desktop.
Get your local IP address
This file contains hidden or 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
require 'socket' | |
def local_ip | |
orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true # turn off reverse DNS resolution temporarily | |
UDPSocket.open do |s| | |
s.connect '64.233.187.99', 1 | |
s.addr.last | |
end | |
ensure | |
Socket.do_not_reverse_lookup = orig | |
end | |
puts local_ip | |
# http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment