module LogMagic::PortUtils

Public Class Methods

port_open?(ip, port) click to toggle source

copied from stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open

# File lib/log_magic/utils/port_utils.rb, line 7
def self.port_open?(ip, port)
  begin
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(ip, port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
    end
  rescue Timeout::Error
  end

  return false
end