Hello, I'm pretty much a complete newbie when it comes to Perl. I'm trying to create a small script to verify that telnet is active on a server, then log off and go to the next sequentially numbered server. Any errors I want dumped to a log file for review.

I think I have all of this working, EXCEPT that for some reason it fails to recognize that it is succeeding at logging in to the server, and then times out. The prompt char is a ">" which looks like it's included in the prompt portion ( Prompt => '/[\$%#>]\ $/');).

I've checked my error logs (dump.log), and I see that it logs in and gets to the prompt -- the script just doesn't recognize the prompt. It reads in the telnet login message and all.

Can anybody help me decipher the prompt portion or point out where I went wrong? I'm having trouble finding more examples/documentation on net::Telent online beyond the basic documentation file.

#!/usr/bin/perl use strict; use Net::Telnet (); #Trying to get default values working here -- still working on it my $clearfile; my $ipbase; # = shift || "192.168.1"; my $ipcurrent; # = shift || '1'; my $ipend; # = shift || '255'; my $port; # = shift || '23'; my $username; my $password; my $telnet; #This is the log file generated by any failed connections my $downreport = 'report.log'; print "Do you want to keep the old log file and append the new info? [ +y/n]\n"; $clearfile=<stdin>; chomp ($clearfile); if ($clearfile eq "n"){ open(INFO,">$downreport"); print INFO "\n";} #Grabbing all pertinent information -- the defaults are not there yet print "What is the base IP? (Example: 192.168.1)\n"; $ipbase = <stdin>; chomp ($ipbase); print "What is the bottom IP? (Default 1)\n"; $ipcurrent = <stdin>; chomp ($ipcurrent); print "What is the top IP? (Default 255)\n"; $ipend = <stdin>; chomp ($ipend); print "What port would you like to connect to (Default 23)?\n"; $port = <stdin>; chomp ($port); print "Username:"; $username = <stdin>; chomp ($username); #I would like to find a way to turn off echo or mask this portion print "Password:"; $password = <stdin>; chomp ($password); for($ipcurrent .. $ipend){ print "Connecting to $ipbase.$ipcurrent\n"; #This is the TRY part of the try-catch portion, where it tries to conn +ect #If it doesn't it outputs the error without killing the program eval { #Sets parameters for the telnet session $telnet = new Net::Telnet->new( Timeout=>3,Dump_Log=>'dump.log', input +_log=>'input.log', output_log=>'output.log', Port=>$port, Prompt => '/[\$%#>]\ $/'); die &Log_Message("Can't open telnet session to the remote host") unles +s #warn &Log_Message("Can't open telnet session to remote host") unless $telnet; #opens the particular IP that we're at. Not sure if these "die" comma +nds are necessary $telnet->open("$ipbase.$ipcurrent"); #die ("Cannot open $ipbase.$ipcurrent\n"); #This may need some tweaking depending on the log-on format $telnet->login( Name=>"$username", Password=>"$password"); print "Logged on\n"; print $telnet->getline; #once connected it tries to exit cleanly $telnet->print("exit"); }; #The other part was try, this is the CATCH. It catches the errors and +logs them if ($@){ print $@; print "$ipbase.$ipcurrent failed.\n"; open(INFO, ">>$downreport"); print INFO "Failure at \t $ipbase.$ipcurrent \t Please investigate +.\n"; }; print "Trying the next IP\n"; #Stepping up to the next IP $ipcurrent++; } exit 0;


In reply to Login failure with net::Telnet by unixgeek

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.