Guest User

Untitled

a guest
Jul 1st, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.00 KB | None | 0 0
  1. ### This script is designed to telnet into a Cisco router, issue a set of commands intended to "break" the configuration
  2. ### and then disconnect from the telnet session.
  3. ############################################################################
  4. ############################################################################
  5.  
  6. use Net::Telnet ();
  7.  
  8.  
  9. $username = "yourUSER";
  10. $password = "yourPASS";
  11.  
  12.  
  13.  
  14. @issue_commands = (
  15. 'enable',
  16. 'configure terminal',
  17. 'interface eth 0/1',
  18. 'shutdown',
  19. 'exit',
  20. );
  21.  
  22.  
  23.  
  24.  
  25. #make the telnet connection        
  26. $t = new Net::Telnet (Timeout => 10,Prompt => '/[\$%#>] $/');
  27. $t->open("$server");
  28. $t->login($username, $password);
  29.    
  30.  
  31.    
  32.    
  33. #loop through this function for every entry in the @issue_commands array
  34. foreach $command (@issue_commands){
  35.    
  36.     #issue the command and store it in the array @telnet_output
  37.     @telnet_output = $t->cmd($command);
  38.  
  39.     #dump contents of @telnet_output array to the screen
  40.     foreach(@telnet_output){
  41.         chomp;
  42.         print "$_\n";
  43.         }
  44. }
Add Comment
Please, Sign In to add comment