Hi monks

I am using Net::SSH::Perl module to connect to a firewall from a windows 2000 machine.Following is my script

#!/usr/local/bin/perl -w # Steps: # 1. login # 2. go to enable mode ('en') # 3. execute 'no pager' to disable paging # 4. execute 'sh access-list access-list-name' # 5. Get hit counts # 6. logout $|++; use strict; use Net::SSH::Perl; use Net::SSH::Perl::Constants qw( :msg ); use constant SKIP_PROMPT => 1; # pix prints login prompt twice, skip + first my $host = shift || die "Usage: $0 pix_name\n"; my $time2login = 10; my $time2run = 20; my $file = "C:\\hit_cnt.txt"; open (DAT, ">>$file") || die "can not open"; # modify these in case of prompt (hostname) changes # assuming alphanumeric characters only: # [a-zA-Z0-9] is actually \w, but some hosts have '_' or '-' in their +names my $enb_prompt = qr/(?:[a-zA-Z0-9]+#)\s*/; # alphanumeric followed b +y '#' my $reg_prompt = qr/(?:[a-zA-Z0-9]+>)\s*/; # alphanumeric followed b +y '>' my $pass_prompt = qr/Password:\s*/; my ($prompt_cnt,$save,$done) = (0,0,0); my ($ssh, @config); # login on the device eval { local $SIG{'ALRM'} = sub { die 'TimedouT' }; alarm $time2login; $ssh = Net::SSH::Perl->new($host, protocol=>1, cipher=>'DES', port= +>22); $ssh->login('USER-NAME','PASSWD'); alarm 0; }; ($@)? ( die '[',scalar localtime,'] ', ($@ =~ /TimedouT/)? "Takes too long to login on $ho +st.\n" : "Unexpected eval err: $@.\n" ) : undef; # set up handler and intercept everything that goes to STDOUT $ssh->register_handler(SSH_SMSG_STDOUT_DATA, sub { my($ssh, $packet) = @_; my $str = $packet->get_str; print DAT "$str"; if ( $save ) { # reading config if ( $str =~ /$enb_prompt$/ ) { # last line of the config + p +rompt my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('exit ' . "\n"); $packet->send; $done++; } $str =~ s/\cM//g; chomp $str; # skip echo of the command and logout sequence push @config, $str unless ( $done || $str =~ /^(\w|\s)$/ +|| $str =~ /^:/ || $str eq '' ); } else { # login part if ($str =~ /$reg_prompt$/) { # go to enable mode $prompt_cnt++; # pix prints login prompt twice +, remember return unless $prompt_cnt > SKIP_PROMPT; my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('enable' . "\n"); $packet->send; $prompt_cnt = 0; # will resuse it in enable mode + } elsif ( $str =~ /$pass_prompt$/ ) { # going into enable mode.... my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str("PASSWD\n"); $packet->send; } elsif ( $str =~ /$enb_prompt$/ && !$prompt_cnt ) { # exec first command in enable mode my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('no pager' . "\n"); $packet->send; $prompt_cnt++; } elsif ( $str =~ /$enb_prompt$/ && $prompt_cnt ) { # exec second command in enable mode, ready to rock my $packet = $ssh->packet_start(SSH_CMSG_STDIN_DATA); $packet->put_str('sh access-list access-list-name' . "\n"); $packet->send; $save++; } else { # Uncomment this for debug purposes # print "Useless data: $str\n"; } } }); eval { local $SIG{'ALRM'} = sub { die 'TimedouT' }; alarm $time2run; $ssh->cmd(''); # thaaaat's right, nothing at all alarm 0; }; ($@)? ( die '[',scalar localtime,'] ', ($@ =~ /TimedouT/)? "Timed out while pulling from $ +host.\n" : "Unexpected eval err: $@.\n" ) : undef;
As I could not install Math::GMP on windows, I installed GMP::BigInt and replaced Math::GMP with Math::BigInt in all the modules. I am using CygWin bash shell. When I execute the script

I got this message with an error

$ perl ssh.pl xxx.xxx.xxx.xxx Nalina: Reading configuration data /home/Administrator/.ssh/config Nalina: Reading configuration data /etc/ssh_config Nalina: Connecting to xxx.xxx.xxx.xxx, port 22. Nalina: Remote protocol version 1.5, remote software version Cisco-1.2 +5 Nalina: Net::SSH::Perl Version 1.25, protocol version 1.5. Nalina: No compat match: Cisco-1.25. Nalina: Connection established. Nalina: Waiting for server public key. Nalina: Received server public key (768 bits) and host key (2048 bits) +. Nalina: Host 'xxx.xxx.xxx.xxx' is known and matches the host key. [Tue Jun 22 11:53:30 2004] Unexpected eval err: Undefined subroutine & +Math::BigI nt::sizeinbase_gmp called at /usr/lib/perl5/site_perl/5.8.2/Net/SSH/Pe +rl/Util/RS A.pm line 30.
What is the compatible function for sizeinbase_gmp in BigInt?

Regards

Nalina

Edited by Chady -- added code tags.


In reply to Replcing Math::GMP with Math::BigInt by Nalina

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.