#!/usr/bin/perl #use strict; use warnings; use Expect; open WRITE, "> output" or die $!; open READ, "ip_address" or die $!; my @ip_array = ; foreach (@ip_array) { chomp ($_); my $command = "ssh"; my @parameters = ("slayedbylucifer\@$_", "uptime"); my $exp = new Expect; $exp->raw_pty(1); $exp->spawn($command, @parameters) or die "Cannont spwan $command: $!\n"; $exp->log_stdout(0); # stop the output going to STDOUT my $timeout=10; $exp->expect($timeout, [ qr/yes/ => sub { my $exp = shift; $exp->send("yes\r"); exp_continue; } ], [qr/assword/i => sub { my $exp = shift; $exp->send("12345\n"); exp_continue; } ] ); if ($? == 0) { print WRITE "The password is correct for \"slayedbylucifer\" on $_\n"; ######### Let's su and check the password for root ####### my $command1 = "su"; my @parameters1 = ("-"); my $exp1 = new Expect; $exp1->raw_pty(1); $exp->spawn($command1, @parameters1) or die "Cannt spawn $command1: $!\n"; $exp->expect($timeout, [qr/assword/i => sub { my $exp1 = shift; $exp->send("root_password\n"); exp_continue; } ] ); if ( $? == 0 ) { print WRITE "The password is correct for \"root\" on $_\n"; } else { print WRITE "The password is wrong for \"root\" on $_\n"; } } else { print WRITE "The password is wrong for \"slayedbylucifer\" on $_\n"; } } close WRITE; #### Cannot reuse an object with an already spawned command at ./ping.pl line 43