Reputation: 485
I need to get the remote sshd version using Net::SSH2 from a windows
./check_ssh -H exemple.com
OpenSSH_6.0p1 (Protocol 2.0)
In case the ssh is shutdown just display Connection refused or Socket Timeout if the connection is not specifically refused.
The end purpose would be to simulate the behavior of check_ssh nagios plugin from a windows box. I will be connecting from that windows box to an unix appliance and send the results of my script to nagios via nrpe.
I do not need to login. I have been trying to install in dwim perl Net::SSH::Perl without success the only one I managed to install was Net::SSH2. I do not need support for ssh v1.
Upvotes: 0
Views: 312
Reputation: 351
You can use the IO::Socket::INET
module. For example:
$ cat ssh.pl
#!/usr/bin/perl
use IO::Socket::INET;
my $socket = IO::Socket::INET->new(
PeerHost => 'localhost',
PeerPort => 22,
);
$socket->print("\n");
my $output = join '', $socket->getlines();
print $output;
What the output would look like:
$ ./ssh.pl
SSH-2.0-OpenSSH_6.2
Protocol mismatch
From this point you simply need to parse the output.
Upvotes: 2
Reputation: 351
If you can install the netcat utility you could use that to check it. For example:
my $NC = `nc -w 1 localhost 22`;
print $NC;
In this example netcat connects to localhost on port 22 and times out after 1 second.
Upvotes: 0