Click here to get back home

Net::Telnet $prematch, $match

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Net::Telnet $prematch, $match ton de w 04-12-2007
Posted by ton de w on April 12, 2007, 10:18 am
Please log in for more thread options


Hello,
I am looking at a code fragment that I dont understand properly.
..
my ($prematch, $match) = $telnet->waitfor('/login: $i);
$telnet->print($user);
if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
password'))
{
crash out - cannot go on
}
my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
my($prematch, $match) = $telnet->print($password);
...

So what I do understand is line1 we wait for "login: " case
insensitive.
Then line2 supply the user - ($prematch, $match) not used at this
point.
line 3 - i am not really sure - $prematch contains the match up to
expression and $match the match expression but what is the if
statement comparing?
And how if we dont get the 'Choose new password' do we continue to
provide the password?

Actually I need to extend this program to do very similar things - is
there an alternative way of doing this?

TIA

Ton


Posted by Jim Gibson on April 12, 2007, 3:16 pm
Please log in for more thread options



> Hello,
> I am looking at a code fragment that I dont understand properly.
> ..
> my ($prematch, $match) = $telnet->waitfor('/login: $i);

I think you need '/login: $/i' there.

> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }
> my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
> my($prematch, $match) = $telnet->print($password);
> ...
>
> So what I do understand is line1 we wait for "login: " case
> insensitive.
> Then line2 supply the user - ($prematch, $match) not used at this
> point.
> line 3 - i am not really sure - $prematch contains the match up to
> expression and $match the match expression but what is the if
> statement comparing?
> And how if we dont get the 'Choose new password' do we continue to
> provide the password?

My guess: check for a Timeout parameter in the call to new(). Also
check for a Errmode parameter or a call to errmode. My guess is that
your call to waitfor(string=>'Choose ...') is timing out and proceeding
to the next call (waitfor('/password: $/i');)

Note: it helps if you post a complete, minimal program so we don't have
to guess at what is going on.

>
> Actually I need to extend this program to do very similar things - is
> there an alternative way of doing this?

There is the Expect program:
<http://en.wikipedia.org/wiki/Expect>
<http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod>

or the Perl Expect.pm module:
<http://search.cpan.org/~rgiersig/Expect-1.20/Expect.pod>.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Posted by Mumia W. on April 12, 2007, 4:11 pm
Please log in for more thread options


On 04/12/2007 09:18 AM, ton de w wrote:
> Hello,
> I am looking at a code fragment that I dont understand properly.
> ...
> my ($prematch, $match) = $telnet->waitfor('/login: $i);
> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }

I'm assuming that the "errmode" is "return." When the second
$telnet->waitfor() succeeds, the method will return a list containing
values for $prematch and $match. If that happens, it means that the host
is demanding a new password, and since the script can't handle that, it
exits. The "if" statement tests whether a non-empty list was returned by
$telnet->waitfor().


> [...]


Similar ThreadsPosted
Help with Net::IP::Match and mod_perl September 8, 2004, 8:13 pm
Re: match nested tags May 3, 2006, 5:20 pm
Net::Netmask -> match usage problems April 14, 2005, 10:03 am
DBD::mysql object version 2.9003 does not match bootstrap parameter March 4, 2005, 9:00 am
How do you telnet from 1 host to another using Telnet Module December 21, 2005, 4:15 pm
net::telnet to ms telnet server May 19, 2005, 12:28 am
Net::Telnet December 9, 2004, 11:33 pm
NET::Telnet February 15, 2006, 8:42 am
Net::telnet June 9, 2006, 1:42 am
net::telnet problem July 23, 2004, 6:46 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap