Advertisement
Guest User

Untitled

a guest
Jun 11th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #!/usr/bin/perl -I/home/fox/perl5/lib/perl5/Net/
  3. use warnings;
  4. use strict;
  5. use diagnostics;
  6. use Expect;
  7. use Net::OpenSSH;
  8.  
  9. my $cmd = 'printf "hello.\n"';
  10. my $null = '';
  11. # print "What host are you trying to connect to?.\n";
  12. # my $host = <STDIN>;
  13.  
  14. print "ENTER YOUR USERNAME.\n";
  15. my $user = <STDIN>;
  16. chomp($user);
  17.  
  18. print "ENTER YOUR PASSWORD.\n";
  19. my $pass = <STDIN>;
  20. chomp($pass);
  21.  
  22. my @lines = ("shell.xShellz.com");
  23.  
  24. #my $date = localtime();
  25. #$date = my($day, $month, $year)=(localtime)[3,4,5];
  26. #print "$day-".($month+1)."-".($year+1900)."\n";
  27.  
  28. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  29. localtime(time);
  30.  
  31. my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  32. print "$abbr[$mon] $mday";
  33. my $date = "$mday-$mon-$year";
  34.  
  35. foreach my $host (@lines) {
  36. #$host", timeout => 30
  37. chomp($host);
  38. print "$host";
  39. if ($host eq $null) {
  40. die "You need a host to SSH!.\n";
  41. } elsif ($user eq $null) {
  42. die "You need a user to log into the host.\n";
  43. } elsif ($pass eq $null) {
  44. die "You need a password to SSH!.\n";
  45. } else {
  46. if ($host eq $host) {
  47. print "Connecting to $host.....................\n";
  48. use Net::OpenSSH;
  49. my $login_string = $user . ':' . $pass . '@' . $host;
  50. my $ssh = Net::OpenSSH->new("$host",
  51. user => "$user",
  52. passwd => "$pass",
  53. master_opts => [-o => "StrictHostKeyChecking=no"],
  54. timeout => "15");
  55. #$login_string);
  56. $ssh->error and die "unable to connect to remote host: ". $ssh->error;
  57. my @results = $ssh->capture2('printf "hello.\n"');
  58. map { print;} @results;
  59. my @output = "@results";
  60.  
  61. my $file = "$host-$date.txt";
  62. open (FILE, ">> $file") || die "problem opening $file\n";
  63. print FILE @output;
  64. close(FILE);
  65. }
  66. else {
  67. print "failed";
  68. die "Failed to connect, check your settings.\n";}
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement