Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Text::CSV;
- use Net::Telnet ();
- my ($i, $archivo_final);
- my $csv = Text::CSV->new({ sep_char => ',' });
- my $file = $ARGV[0] or die "Necesito un fichero CSV como parámetron";
- open (my $data, '<', $file) or die "No puedo abrir el fichero $file $!n";
- while (my $line = <$data>){
- chomp $line;
- if( $csv->parse($line)){
- my @fields = $csv->fields();
- my $telnet = Net::Telnet->new(
- Timeout => 5,
- Errmode => 'return',
- Host => "$fields[1]",
- Port => 23,
- Binmode => 0,
- );
- if(!$telnet){
- print "Host Inaccessible: $fields[1]n";
- $archivo_final = "$fields[0],$fields[1],$fields[2]";
- open(INC,">>Inaccessible.csv");
- print INC $archivo_final."n";
- close(INC);
- $i++;
- next;
- }elsif($telnet){
- if($telnet->waitfor('/password[: ]*$/i')){
- print "Host Zyxel: $fields[1]n";
- $telnet->print('soy_cgrc_admin');
- $telnet->waitfor('/:/');
- $telnet->cmd('99'); # ejemplo de ejecución de un comando
- $archivo_final = "$fields[0],$fields[1],$fields[2]";
- open(ZYX,">>ZyxelHost.csv");
- print ZYX $archivo_final."n";
- close(ZYX);
- $i++;
- }else{
- print "Other Host: $fields[1]n";
- $archivo_final = "$fields[0],$fields[1],$fields[2]";
- open(OTH,">>OtherHost.csv");
- print OTH $archivo_final."n";
- close(OTH);
- $i++;
- }
- }
- $telnet->close;
- }else{
- warn "la linea no se ha podido procesar: $linen";
- }
- }
- close($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement