Capture the master stderr stream and check it
See here how to do it.
Another approach you can use is just to open a
socket to the remote SSH server. The first thing
it sends back is its version string. For
$ nc localhost 22
From that information you should be able to
infer if the server supports SSH v2 or not.
Finally, if you also need to talk to SSH v1
servers, the development version of my other
module Net::SSH::Any is able to do it
using the OS native SSH client, though it
establishes a new SSH connection for every
my $ssh =
strict_host_key_checking => 0);
Update: In response to Bill
comment below on the issue of sending multiple
commands over the same session:
The problem of sending commands over the same
session is that you have to talk to the remote
shell and there isn't a way to do that reliably in
a generic fashion as every shell do things
differently, and specially for network equipment
shells that are quite automation-unfriendly.
Anyway, there are several modules on CPAN
trying to do that, implementing a handler for
every kind of shell (or OS). For instance, check
Oliver Gorwits's modules Net::CLI::Interact, Net::Appliance::Session and Net::Appliance::Phrasebook. The
phrasebook approach seems quite suitable.