
07.03.2008, 11:17
|
|
Познавший АНТИЧАТ
Регистрация: 27.04.2007
Сообщений: 1,044
С нами:
10021597
Репутация:
905
|
|
Ну и по просьбе трудящихся на перле. Необходим модуль Net::SSH2
Код:
#!/usr/bin/perl
use Fcntl ':mode';
use Net::SSH2;
###### Config options ######
$input_file = 'ssh.txt';
$bad_file = 'bad.txt';
$good_file = 'good.txt';
############################
$res = getfilestat ($input_file);
die $input_file . ": error: " . $! . "\n" if ($res < 0);
open (INPUT, "<$input_file") || die "$input_file: error: " . $! . "\n";
open (BAD, ">$bad_file") || die "$bad_file: error: " . $! . "\n";
open (GOOD, ">$good_file") || die "$good_file: error: " . $! . "\n";
while (<INPUT>)
{
$_ =~ s/\n$//;
$_ =~ s/\s*$//;
$_ =~ s/^\s*//;
$_ =~ s/\s+/ /g;
($host, $user, $pass) = (split (/ /, $_))[0,1,2];
$ssh = Net::SSH2->new ();
$ssh->connect ($host, 22) || die "$host: connection refused: " . $! . "\n";
print "Trying $host\@$user:$pass...\n";
$islogin = $ssh->auth_password ($user, $pass);
if (!$islogin)
{
print BAD "$host\@$user:$pass\n";
}
else
{
print GOOD "$host\@$user:$pass\n";
}
}
close GOOD;
close BAD;
close INPUT;
print "Checking complete\n";
exit 0;
sub getfilestat ($)
{
my ($fname) = @_;
my ($mode);
$mode = (stat ($fname))[2];
(($mode & S_IFREG) == S_IFREG) ? return 0 : return -1;
}
|
|
|