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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Cisco PIX show command via Telnet


New User

Mar 7, 2013, 3:37 AM

Post #1 of 1 (1148 views)
Cisco PIX show command via Telnet Can't Post

Hello all,

I recently stumbled upon this Perl script:
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:

use Getopt::Std; # So we can do the processing of the command line options
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 password>\n" if (@ARGV < 6);

exit if (!getopts('r:u:p:e:'));



sub main(){
# 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;
kill("TERM", $childpid);
# the else{} block runs only in the child process
else {
print $handle $username."\n" if $username; # Use a username 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);

#calculate the connected users
{ 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.

Many thanks,


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

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