Getting Local ip Address

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
p= local_ip
puts p

Comments

david said…
You got your code from this article: http://coderrr.wordpress.com/2008/05/28/get-your-local-ip-address/

Don't forget to cite your sources ;-)
oops sorry missed it some way :)

Popular posts from this blog

Install Cpanm module error : No such file or directory opening compressed index

How to increase Elasticsearch Shard recovery Speed

Getting started with Python Flask application with MVC structure