#!/usr/bin/perl ## modules to use use strict; use warnings; use Net::Telnet; use Data::Dumper; #$|++; # ## establish some global variables my $HOSTNAME = "10.2.200.10"; my $HOSTPORT = "2033"; my $input_file = 'input.log'; my $output_file = 'output.log'; my $option_file = 'option.log'; my $dump_file = 'dump.log'; my $conn = new Net::Telnet ( Timeout => "3", Errmode => \&error_sub, #Errmode => "return", #Dump_Log => $dump_file, Input_log => $input_file, #Option_log => $option_file, #Output_log => $output_file, Output_record_separator => "", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/' ); # open connection to host $HOSTNAME and port $HOSTPORT # and die if there is a problem unless ($conn->open(Host => $HOSTNAME, Port => $HOSTPORT)) { die "Error opening socket:: ".$conn->errmsg(); } print "Connected to ".$conn->host().", port ".$conn->port()."\n"; # Force the password prompt to be displayed by sending a ^M $conn->print(" "); $conn->waitfor('/Password:/'); $conn->print("password\n"); #Regex to match most IOS devices $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); $conn->cmd("term length 0\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); $conn->cmd("term width 120\n"); $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); my @num = $conn->cmd(String => "show clock\n", Prompt => '/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print Dumper(\@num); print STDERR Dumper(\@num); my @output = (); $conn->print("show version\n"); my (undef, $process_string) = $conn->waitfor('/(?m:^[\w.-]+\s?(?:\(config[^\)]*\))?\s?[\$#>]\s?(?:\(enable\))?\s*$)/'); print $process_string . "\n"; print STDERR $process_string; print Dumper($process_string); sub error_sub{ my $error = shift; print "Made it to error method " . Dumper($error, \@_); }