Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Using Net::Telnet

by TStanley (Canon)
on Mar 05, 2008 at 18:14 UTC ( #672238=perlquestion: print w/ replies, xml ) Need Help??
TStanley has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to connect to an Adtran TSU-IQ frame modem via its telnet interface, but I am having a bit of an issue actually working with its menu based interface. My short script is below:
#!C:\perl\bin\perl -w use Net::Telnet; my $NT = new Net::Telnet(); $NT->open('128.999.999.999'); #obviously not the IP address $NT->cmd(); my @out1 = $NT->cmd('1\n'); print "OUT1: @out1";
And here is the output from the above script:
C:\Documents and Settings\toms\Desktop>perl isdn.pl OUT1: ©[3;1H______________________________________________________________ +___________ ______©[5;1H©[5;1H 1 - Local Login ©[6;1H 2 - Remote Login ©[7;1H 3 - Logout ©[23;1H_____________________________________________________________ +___________ _______©[24;2H©[KEnter Selection -
I am trying to enter option 1, which is the local login. If I try to pass '1' again using the cmd method, it merely repeats the output again. Any suggestions would be greatly appreciated.

TStanley
--------
People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

Comment on Using Net::Telnet
Select or Download Code
Re: Using Net::Telnet
by pc88mxer (Vicar) on Mar 05, 2008 at 18:32 UTC
    It is possible that the trailing newline is the culprit. Note that when you use
    $NT->cmd("1\n");

    you will be sending two newlines - the one you specified in the argument to cmd and one that Net::Telnet will add to the end of each command line.

    You can try using the put method or setting the output_record_separator to the empty string.

      Since TStanley wasn't using double-quotes, but single-quotes, what was actually being sent by cmd was "1\\n\n", or, literally, 1\n followed by a line-terminator. The other end would compare that against "1", "2", and "3", find it didn't match any, and try again.

      Changing it to double quote as you said would send two newlines, which I doubt the other end would play nice with. I think the solution is to just use $NT->cmd(1), but I've not tested that.

Re: Using Net::Telnet
by TStanley (Canon) on Mar 06, 2008 at 20:21 UTC
    Here is some updated code:
    #!C:\perl\bin\perl -w use Net::Telnet; my $NT = new Net::Telnet(); $NT->open('128.999.999.999'); #obviously not my IP my @out = $NT->cmd(); my @out1 = $NT->put('1\n'); my @out2 = $NT->put('password\n'); #obviously not the password print "OUT: @out"; print "OUT1: @out1"; print "OUT2: @out2";
    And here are the results of that code:
    C:\Documents and Settings\toms\Desktop>perl isdn.pl OUT: ADTRAN TSUIQ VER 333a 0464 ©[2J©[1;67HADTRAN TSUIQ©[2;65H(Telnet) EAST1©[1;32HTelnet Login Me +nu ©[3;1H______________________________________________________________ +__________ ______©[5;1H©[5;1H 1 - Local Login ©[6;1H 2 - Remote Login ©[7;1H 3 - Logout ©[23;1H_____________________________________________________________ +__________ _______©[24;2H©[KEnter Selection -OUT1: 1OUT2: 1 C:\Documents and Settings\toms\Desktop>

    TStanley
    --------
    People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://672238]
Approved by pc88mxer
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-08-20 17:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (120 votes), past polls