Hello all, I recently stumbled upon this Perl script: http://forums.cacti.net/about14410.html It is designed to connect to a Cisco PIX firewall via telnet, execute a show command, and then count the number of lines in that output that contain the word 'authenticated' I gave it a whirl and entered in the parameters (IP and the 2 passwords). I even broke out wireshark to see the telnet connection and the commands getting sent. It appears that Perl successfully authenticates with the PIX, but then I'm unsure whether it gets any further. The code for this script is:
#!/usr/bin/perl use Getopt::Std; # So we can do the processing of the command line opt +ions use IO::Socket; # For the connection $port = '23'; #telnet port $timeout=20; #connection timeout # Process the command line options die "Usage: $0 -r <router> -u <username> -p <password> -e <enable pass +word>\n" if (@ARGV < 6); exit if (!getopts('r:u:p:e:')); $username=$opt_u; $password=$opt_p; $enpassword=$opt_e; $router=$opt_r; main(); sub main(){ $i=0; # create a tcp connection to the specified host and port $handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $router, PeerPort => $port, Timeout => $timeout) or return (print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!!!!\nCan't connect to port $port on $router\n!!!!!!!!!!!!!!!!!!!!!!! +!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); # split the program into two processes, identical twins die "can't fork: $!" unless defined($childpid = fork()); # the if{} block runs only in the parent process if ($childpid) { # copy the socket to array while (defined ($line = <$handle>)) { @strings[$i] = $line; $i++; } kill("TERM", $childpid); } # the else{} block runs only in the child process else { print $handle $username."\n" if $username; # Use a use +rname only if there is one; print $handle $password."\n"; print $handle "enable\n"; print $handle $enpassword."\n"; print $handle "sh uauth\n"; print $handle "exit\n"; close ($handle); exit; } #calculate the connected users $i=0; { foreach (@strings) {$i++ if /authenticated/; } print $i; } }
The goal is to have a value returned which is equal to the amount of authenticated users (indicated by the amount of lines in the 'show uauth' command. Is there any glaring errors which may be stopping this script from completing successfully? I always seem to get a '0' returned, but I believe that is just the detault. Any help would be a huge help. Thanks Monks. Regards, Kyle

In reply to Cisco PIX show command via telnet - unable to retrieve correct value by kylet

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.