sub telnet_connection{ my $targetHost = $_[0]; #my $uname = $_[1]; #my $pword = $_[2]; my @listOfCommands = @{$_[3]}; if($verbose){print "\t\tAttempting telnet connection to $targetHost\n"; } eval{ $telnet = Net::Telnet->new( Timeout=>5, Errmode=>'return', dump_log=>"dump_log.txt", input_log=>"input_log.txt"); $telnet->open($targetHost); $telnet->waitfor('/Username: $/i'); $telnet->print($username); $telnet->waitfor('/PASSCODE: $/i'); $telnet->print($password); $telnet->waitfor('/\>/'); #for(my $j=0; $j le scalar @listOfCommands; $j++) foreach my $command (@listOfCommands) { if($verbose) { print "\t\tClient: " . $targetHost . " Command: $command\n"; } if($verbose) { print "\t\tExecuting command: $command\n"; } my @output = $telnet->cmd($command); if($verbose) { print "OUTPUT:\n"; print @output; } logging($targetHost, \@output, "0"); } $telnet->close(); }; if($telnet->errmsg) { logging($targetHost,$telnet->errmsg,"1"); print $@; } }