Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #!/usr/bin/perl -I/home/fox/perl5/lib/perl5/Net/
- use warnings;
- use strict;
- use diagnostics;
- use Expect;
- use Net::OpenSSH;
- my $cmd = 'printf "hello.\n"';
- my $null = '';
- # print "What host are you trying to connect to?.\n";
- # my $host = <STDIN>;
- print "ENTER YOUR USERNAME.\n";
- my $user = <STDIN>;
- chomp($user);
- print "ENTER YOUR PASSWORD.\n";
- my $pass = <STDIN>;
- chomp($pass);
- my @lines = ("shell.xShellz.com");
- #my $date = localtime();
- #$date = my($day, $month, $year)=(localtime)[3,4,5];
- #print "$day-".($month+1)."-".($year+1900)."\n";
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
- localtime(time);
- my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
- print "$abbr[$mon] $mday";
- my $date = "$mday-$mon-$year";
- foreach my $host (@lines) {
- #$host", timeout => 30
- chomp($host);
- print "$host";
- if ($host eq $null) {
- die "You need a host to SSH!.\n";
- } elsif ($user eq $null) {
- die "You need a user to log into the host.\n";
- } elsif ($pass eq $null) {
- die "You need a password to SSH!.\n";
- } else {
- if ($host eq $host) {
- print "Connecting to $host.....................\n";
- use Net::OpenSSH;
- my $login_string = $user . ':' . $pass . '@' . $host;
- my $ssh = Net::OpenSSH->new("$host",
- user => "$user",
- passwd => "$pass",
- master_opts => [-o => "StrictHostKeyChecking=no"],
- timeout => "15");
- #$login_string);
- $ssh->error and die "unable to connect to remote host: ". $ssh->error;
- my @results = $ssh->capture2('printf "hello.\n"');
- map { print;} @results;
- my @output = "@results";
- my $file = "$host-$date.txt";
- open (FILE, ">> $file") || die "problem opening $file\n";
- print FILE @output;
- close(FILE);
- }
- else {
- print "failed";
- die "Failed to connect, check your settings.\n";}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement