summaryrefslogtreecommitdiff
path: root/config/initializers/connectivity_check.rb
blob: 583f372972c7dac9cade64e80ef0c38af11faa7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'socket'
require 'timeout'

module Connectivity
	
	def self.port_open?( ip_addr, port )
		begin
			Timeout::timeout(5) {
				s = TCPSocket.new( ip_addr, port )
				s.close
				return true
			}
		rescue Errno::ECONNREFUSED
		rescue Errno::EHOSTUNREACH
		rescue Errno::EADDRNOTAVAIL
		rescue SocketError
		rescue Timeout::Error
		end
		
		return false
	end

end