use strict; use warnings; use Net::SSH::Expect; my $timeout = 2; # sec my $target = shift or die "No user\@host specified.\n"; my ($user, $host) = split /\@/, $target; my $port; # = 21; if ($host =~ s/:(\d+)$//) { $port = $1; } warn "Testing $user at $host...\n"; ### non password : my $ssh = Net::SSH::Expect->new( host => $host, user => $user, port => $port, password => 'random', raw_pty => 1 , ); $ssh->run_ssh() or die "ERROR: Failed to start the ssh process.\n"; my $output; eval { $output = $ssh->read_all($timeout); }; if (!$@ && defined $output && $output =~ /\S/) { warn "Host $user at $host has sshd:\n$output\n"; } else { warn "Oops...seems not...\n" . ($@ ? $@ : ''); }