Class: ItTools::VpnTools

Inherits:
Object
  • Object
show all
Defined in:
lib/it_tools/it_tools.rb

Instance Method Summary collapse

Instance Method Details

#is_port_open?(ip, port) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/it_tools/it_tools.rb', line 6

def is_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

#on_vpnObject



22
23
24
25
26
27
28
# File 'lib/it_tools/it_tools.rb', line 22

def on_vpn
  if is_port_open?("spicevan.com", 22)
    return FALSE
  else
    return TRUE
  end
end