CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [FishMonger] Problem with Aruba device using plink through IPC::Run: Edit Log



diesel_den
Novice

Jun 7, 2009, 8:53 AM


Views: 3120
Re: [FishMonger] Problem with Aruba device using plink through IPC::Run

I have created an example that works in the same way and have the same problem even using telnet.


Code
use IPC::Run qw( start pump finish timeout ); 

my $username = '<username, 7 characters>';
my $password = '<password, 6 characters>';
my $epassword = '<enable_password, 6 characters>';

my $vars = {};
$vars->{handle} = undef;
$vars->{in} = undef;
$vars->{out} = undef;
$vars->{err} = undef;

my @cmd = ();
push( @cmd, 'plink' );
push( @cmd, '-v', '-a', '-x' ); # Verbose output, disable agent forwarding, and disable X11 forwarding
push( @cmd, '-telnet' );
push( @cmd, '-l', $username );
#push( @cmd, ( '-pw', $password ) ) if $password;
#push( @cmd, '-' . $this->{version} ) if $this->{version} =~ /^[12]$/;
#push( @cmd, '-C' ) if $this->{compression};
#push( @cmd, ( '-P', $this->{port} ) );
push( @cmd, '<ip_of_device>' );

print "Connecting to the device...\n";
$vars->{handle} = start \@cmd, \$vars->{in}, \$vars->{out}, \$vars->{err}, timeout(100);
print "Connected\n";

my_wait_for('User:\s', $vars);
my_send($username, $vars);

my_wait_for('Password:\s', $vars);
my_send($password, $vars);

my_wait_for('\(Aruba\)\s>', $vars);
my_send('enable', $vars);

my_wait_for(':', $vars);
my_send($epassword, $vars);

my_wait_for('\(Aruba\)\s#', $vars);
my_send('config term', $vars);

my_wait_for('\(Aruba\)\s\(config\)\s#', $vars);
my_send('enable', $vars);

my_wait_for('Password:', $vars);
my_send($epassword, $vars);

my_wait_for('password:', $vars);
my_send($epassword, $vars);

my_wait_for('#', $vars);
my_send('exit', $vars);

my_wait_for('#', $vars);

sub my_wait_for
{
my $regex = shift;
my $vars = shift;

print "\n>>my_wait_for: $regex\n";
until ( $vars->{out} =~ /$regex$/ )
{
$vars->{handle}->pump();
print "\n out: $vars->{out}\n";
}
}

sub my_send
{
my $input = shift;
my $vars = shift;

print "\n>>my_send: $input\n";
$vars->{in} .= $input . "\n";
while ( $this->{in} )
{
print "\n in: $in";
$vars->{handle}->pump();
print "\n out: $vars->{out}\n";
}
}


Output of the program:

Code
Connecting to the device... 
Connected

>>my_wait_for: User:\s

out:

out:

out:
(Aruba)
User:

>>my_send: xxxxxxx

>>my_wait_for: Password:\s

out:
(Aruba)
User:

out:
(Aruba)
User: x

out:
(Aruba)
User: xxxxxxx
Password:

>>my_send: yyyyyy

>>my_wait_for: \(Aruba\)\s>

out:
(Aruba)
User: xxxxxxx
Password:

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >

>>my_send: enable

>>my_wait_for: :

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >e

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:

>>my_send: zzzzzz

>>my_wait_for: \(Aruba\)\s#

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:*

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #

>>my_send: config term

>>my_wait_for: \(Aruba\)\s\(config\)\s#

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #c

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #configure term
Enter Configuration commands, one per line. End with CNTL/Z

(Aruba) (config) #

>>my_send: enable

>>my_wait_for: Password:

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #configure term
Enter Configuration commands, one per line. End with CNTL/Z

(Aruba) (config) #e

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #configure term
Enter Configuration commands, one per line. End with CNTL/Z

(Aruba) (config) #enable
Password:

>>my_send: zzzzzz

>>my_wait_for: password:

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #configure term
Enter Configuration commands, one per line. End with CNTL/Z

(Aruba) (config) #enable
Password:*

out:
(Aruba)
User: xxxxxxx
Password: ******
(Aruba) >enable
Password:******
(Aruba) #configure term
Enter Configuration commands, one per line. End with CNTL/Z

(Aruba) (config) #enable
Password:*******


As you see, we have response "*******" instead of "****** Re-Type password:".


(This post was edited by diesel_den on Jun 7, 2009, 11:59 AM)


Edit Log:
Post edited by diesel_den (Novice) on Jun 7, 2009, 9:03 AM
Post edited by diesel_den (Novice) on Jun 7, 2009, 11:59 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives