Guest User

Untitled

a guest
Apr 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.29 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use Fcntl ':mode';
  4. use Net::SSH2;
  5. ###### Config options ######
  6. $input_file = 'ssh.txt';
  7. $bad_file = 'bad.txt';
  8. $good_file = 'good.txt';
  9. ############################
  10.  
  11. $res = getfilestat ($input_file);
  12. die $input_file . ": error: " . $! . "\n" if ($res < 0);
  13.  
  14. open (INPUT, "<$input_file") || die "$input_file: error: " . $! . "\n";
  15. open (BAD, ">$bad_file") || die "$bad_file: error: " . $! . "\n";
  16. open (GOOD, ">$good_file") || die "$good_file: error: " . $! . "\n";
  17. while (<INPUT>)
  18. {
  19.   $_ =~ s/\n$//;
  20.   $_ =~ s/\s*$//;
  21.   $_ =~ s/^\s*//;
  22.   $_ =~ s/\s+/ /g;
  23.   ($host, $userr, $passs) = (split (/ /, $_))[0,1,2];
  24.   $user = 'root';
  25.   $pass = 'root';
  26.   $ssh = Net::SSH2->new ();
  27.   $ssh->connect ($host, 22, Timeout=>7); # || die "$host: connection refused: " . $! . "\n";
  28.   #print "Trying $host\@$user:$pass...\n";
  29.   $islogin = $ssh->auth_password ($user, $pass);
  30.   if (!$islogin)
  31.   {
  32.     print "$host\n";
  33.     #print BAD "$host\@$user:$pass\n";
  34.   }
  35.   else
  36.   {
  37.     print "$host\n";
  38.     #print GOOD "$host\@$user:$pass\n";
  39.   }
  40. }
  41. close GOOD;
  42. close BAD;
  43. close INPUT;
  44. print "Checking complete\n";
  45. exit 0;
  46.  
  47. sub getfilestat ($)
  48. {
  49.   my ($fname) = @_;
  50.   my ($mode);
  51.  
  52.   $mode = (stat ($fname))[2];
  53.   (($mode & S_IFREG) == S_IFREG) ? return 0 : return -1;
  54. }
Add Comment
Please, Sign In to add comment