diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-12 21:00:16 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-12 21:00:16 +0000 |
commit | 6334b9cdfc47bd85b2ce236572e08406324d25cd (patch) | |
tree | bd0bd3cc279d8377efde2affc8dc223bfb858ca2 /worker/tests/ssh.rb |
Initial dump of code.
Diffstat (limited to 'worker/tests/ssh.rb')
-rwxr-xr-x | worker/tests/ssh.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/worker/tests/ssh.rb b/worker/tests/ssh.rb new file mode 100755 index 0000000..4264c8e --- /dev/null +++ b/worker/tests/ssh.rb @@ -0,0 +1,50 @@ +require 'timeout' + + +# +# Run an SSH test. +# +# +# Return value +# TRUE: The host is up +# +# FALSE: The host is not up +# +def ssh_test ( params ) + + # + # Get the hostname & port to test against. + # + host = params['target_host'] + port = params['test_port'] + + puts "SSH testing host #{host}:#{port}" + + + begin + timeout(3) do + + begin + socket = TCPSocket.new( host, port ) + socket.puts( "QUIT") + + banner = socket.gets(nil) + banner = banner[0,20] + socket.close() + + if ( banner =~ /ssh/i ) + puts "SSH alive: #{banner}" + return true + end + rescue + puts "SSH exception on host #{host}:#{port} - #{$!}" + return false + end + end + rescue Timeout::Error => e + puts "TIMEOUT: #{e}" + return false + end + + return false +end |