Here's what I came up with.. its VERY primitive at this point, and I'll be developing it more so, much thanks to jcwren for his example.. I hope this helps someone out there..
#!/usr/bin/perl # # Purpose: Dial the OOB on a cisco router # and determine the OOB if the # OOB line is up and functioning # properly # # Code by Brad Lhotsky <brad@divisionbyzero.net> # Based off code by jcwren on http://perlmonks.org # $|++; use strict; use Device::SerialPort; ################### # configs. my $DEVICE = '/dev/cua1'; # serial port ext. modem is on my $QUIETDIAL = 0; # Turn on/off the modem speake +r my $USERNAME = 'username' . "\n"; # username for the router my $PASSWORD = 'password' . "\n"; # password for the router my $NUMBER = '912345678'; # routers number my $MAX_RETRY = 3; # number of times we retry my $DEBUG = 1; # print a whole buncha crap? ################### # Globals. my $DONE = 0; my $TOTALIN = 0; my $TOTALOUT = 0; my $SUCCESS = 0; my $ERROR = ""; my $ob = new Device::SerialPort ($DEVICE, 1); die "Couldn't access $DEVICE: $!\n" unless $ob; ################### # setup device print "configuring ... "; sleep(1); $ob->baudrate(9600); $ob->parity('none'); $ob->databits(8); $ob->stopbits(1); $ob->handshake('none'); $ob->stty_icrnl(1); $ob->stty_ocrnl(1); $ob->stty_onlcr(1); $ob->stty_opost(1); $ob->write_settings; print "done.\n"; #################### # Now we need to do # some modem dialing # stuff.. my $init = "ATH0\n"; # modem hangup, clear the line +. my $silence = "ATM0\n"; # silence the speaker my $dial = "ATDT $NUMBER\n"; # dial the number my $count = $ob->write($init); warn "WRITE FAILED!\n" unless $count; warn "WRITE INCOMPLETE!\n" if $count != length($init); select undef, undef, undef, 2.5; # sleep 2.5 seconds. if($QUIETDIAL) { $count = $ob->write($silence); warn "WRITE FAILED!\n" unless $count; warn "WRITE INCOMPLETE!\n" if $count != length($silence); select undef, undef, undef, 2.5; # sleep 2.5 seconds. } $count = $ob->write($dial); warn "WRITE FAILED!\n" unless $count; warn "WRITE INCOMPLETE!\n" if $count != length($dial); #################### # trap ctrl+c here. $SIG{'INT'} = sub { $DONE++; $ob->close; undef $ob; }; my $RETRY = 0; while(!$DONE) { my ($inbytes,$outbytes) = (0,0); (undef, $inbytes, $outbytes, undef) = $ob->status or warn "could not get port status!\n"; $TOTALIN += $inbytes; $TOTALOUT += $outbytes; if(my $line = $ob->input) { if($line =~ /CONNECT\s+(\d+)/i) { # Standard baudrate should be 9600, # but in case its not, we need to # reconfigure our modem. $ob->baudrate($1); $ob->write_settings; sleep(1); # After this point we need ot push "enter" a f +ew times. $ob->write("\n\n"); } elsif($line =~ /sername\:/) { $ob->write($USERNAME); } elsif($line =~ /assword\:/) { $ob->write($PASSWORD); } elsif($line =~ /NO CARRIER/i) { end(\$ob, \$DONE) if ($RETRY >= $MAX_RETRY); $RETRY++; $ob->write($init); select undef, undef, undef, 1.5; $ob->write($dial); } elsif($line =~ /[\w().-]*[\$#>]/) { # prompt # which is all we were looking for! # we're done! and successfully! $DONE++; $SUCCESS++; last; } print $line; } select undef, undef, undef, 0.5; # sleep for half a second. } print "Total bytes: $TOTALIN (in), $TOTALOUT (out)\n"; if($SUCCESS) { end(\$ob); print "successful!\n"; } sub end { my $obref = shift; my $checkref = shift; ref($checkref) && $$checkref++; $ob->write("ATH0\n"); $ob->close; undef $ob; }

welp thats about it.. look for it to go up in its finalized state on http://www.otrics.com where me and my friend (cleen here) are assembling a suite of network monitoring/auditing/configuration/trouble shooting tools for all you network admins out there.. wish us luck.. ;)

-brad..

In reply to Re: Device::SerialPort Examples.. by reyjrar
in thread Device::SerialPort Examples.. by reyjrar

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.