Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Text::CSV;
  5. use Net::Telnet ();
  6.  
  7. my ($i, $archivo_final);
  8. my $csv = Text::CSV->new({ sep_char => ',' });
  9. my $file = $ARGV[0] or die "Necesito un fichero CSV como parámetron";
  10.  
  11. open (my $data, '<', $file) or die "No puedo abrir el fichero $file $!n";
  12. while (my $line = <$data>){
  13. chomp $line;
  14. if( $csv->parse($line)){
  15. my @fields = $csv->fields();
  16. my $telnet = Net::Telnet->new(
  17. Timeout => 5,
  18. Errmode => 'return',
  19. Host => "$fields[1]",
  20. Port => 23,
  21. Binmode => 0,
  22. );
  23. if(!$telnet){
  24. print "Host Inaccessible: $fields[1]n";
  25. $archivo_final = "$fields[0],$fields[1],$fields[2]";
  26. open(INC,">>Inaccessible.csv");
  27. print INC $archivo_final."n";
  28. close(INC);
  29. $i++;
  30. next;
  31. }elsif($telnet){
  32. if($telnet->waitfor('/password[: ]*$/i')){
  33. print "Host Zyxel: $fields[1]n";
  34. $telnet->print('soy_cgrc_admin');
  35. $telnet->waitfor('/:/');
  36. $telnet->cmd('99'); # ejemplo de ejecución de un comando
  37. $archivo_final = "$fields[0],$fields[1],$fields[2]";
  38. open(ZYX,">>ZyxelHost.csv");
  39. print ZYX $archivo_final."n";
  40. close(ZYX);
  41. $i++;
  42. }else{
  43. print "Other Host: $fields[1]n";
  44. $archivo_final = "$fields[0],$fields[1],$fields[2]";
  45. open(OTH,">>OtherHost.csv");
  46. print OTH $archivo_final."n";
  47. close(OTH);
  48. $i++;
  49. }
  50. }
  51. $telnet->close;
  52. }else{
  53. warn "la linea no se ha podido procesar: $linen";
  54. }
  55. }
  56. close($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement