Sha256: 7eda8843613817c9ba87e6fed5e7642e7a7b65a76bb006b31c11db04f5a4942b

Contents?: true

Size: 328 Bytes

Versions: 13

Compression:

Stored size: 328 Bytes

Contents

require 'socket'
require 'timeout'

module SocketHelper
  def is_port_open?(ip, port)
    begin
      Timeout::timeout(1) do
        s = TCPSocket.new(ip, port)
        s.close
        return true
      end
    rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH
      # don't do anything
    end
    false
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
joe_utils-0.1.6 lib/joe_utils/helpers/socket_helper.rb
joe_utils-0.0.12 lib/joe_utils/socket_helper.rb
joe_utils-0.0.11 lib/joe_utils/socket_helper.rb
joe_utils-0.0.10 lib/joe_utils/socket_helper.rb
joe_utils-0.0.9 lib/joe_utils/socket_helper.rb
joe_utils-0.0.8 lib/joe_utils/socket_helper.rb
joe_utils-0.0.7 lib/joe_utils/socket_helper.rb
joe_utils-0.0.6 lib/joe_utils/socket_helper.rb
joe_utils-0.0.5 lib/joe_utils/socket_helper.rb
joe_utils-0.0.4 lib/joe_utils/socket_helper.rb
joe_utils-0.0.3 lib/joe_utils/socket_helper.rb
joe_utils-0.0.2 lib/joe_utils/socket_helper.rb
joe_utils-0.0.0 lib/joe_utils/socket_helper.rb