ssh_test 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ssh_test.rb +50 -0
- metadata +45 -0
data/lib/ssh_test.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Class to test if we can ssh successfully
|
2
|
+
# Coded by Werner Gillmer <werner.gillmer@gmail.com>
|
3
|
+
|
4
|
+
require 'socket'
|
5
|
+
require 'net/ssh'
|
6
|
+
require 'timeout'
|
7
|
+
|
8
|
+
class SSHTest
|
9
|
+
# Test a ssh connection for successfull connection and authentication.
|
10
|
+
# Returns true or false
|
11
|
+
#
|
12
|
+
# Example :
|
13
|
+
# >> ssh = SSHTest.new
|
14
|
+
# >> if ssh.test('127.0.0.1','billgates','/home/billgates/.ssh/id_rsa') == false
|
15
|
+
# >> puts "ERROR"
|
16
|
+
# >> end
|
17
|
+
# => false
|
18
|
+
# => true
|
19
|
+
#
|
20
|
+
# Arguments :
|
21
|
+
# server: (string) valid hostname or IP
|
22
|
+
# username: (string) Username to use for authentication
|
23
|
+
# sshKey: (string) Path including filename to ssh key to use
|
24
|
+
|
25
|
+
|
26
|
+
def test(server,username,sshKey)
|
27
|
+
# Timeout
|
28
|
+
begin
|
29
|
+
Timeout::timeout(5) do
|
30
|
+
# Socket connection
|
31
|
+
begin
|
32
|
+
socket = TCPSocket.new(server,'22')
|
33
|
+
# Authentication
|
34
|
+
begin
|
35
|
+
ssh = Net::SSH.start(
|
36
|
+
server,username,
|
37
|
+
:keys => [sshKey])
|
38
|
+
return true
|
39
|
+
rescue Net::SSH::AuthenticationFailed, Errno::ECONNREFUSED
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
end # End for do from timeout
|
46
|
+
rescue Timeout::Error
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssh_test
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Werner Gillmer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-30 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Test if we can make a successfull ssh connection
|
15
|
+
email: werner.gillmer@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ssh_test.rb
|
21
|
+
homepage: http://github.com/daemonza/SSHTest
|
22
|
+
licenses: []
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 1.8.15
|
42
|
+
signing_key:
|
43
|
+
specification_version: 3
|
44
|
+
summary: Test if we can make a successfull ssh connection
|
45
|
+
test_files: []
|