http://www.perlmonks.org?node_id=567403


in reply to Managing TERM TYPE Option Requests with Net::Telnet

Yup, you're missing a vital call.. It seems that Net::Telnet does in fact use IO::Sockets. You need to add something like:
$data = $nto->answerTelnetOpts($t, $data);
i.e. you need to tell N::T::O to actually do some parsing. What I'm not to sure of, is how you get the raw data out of Net::Telnet. It looks to me like you want to use $t->buffer, and set telnet_mode => 0, but I haven't tried it.

C.

Replies are listed 'Best First'.
Re^2: Managing TERM TYPE Option Requests with Net::Telnet
by initself (Monk) on Aug 16, 2006 at 02:31 UTC

    Excellent! Given your advice, I was able to see how use my telnet object $t as a socket.

    First I set the TERM TYPE Option in the $nto object:

    my %options = (TTYPE => { 'DO' => sub {} },); my $nto = Net::Telnet::Options->new(%options);

    Then I set my telnetmode to 0:

    $t->telnetmode(0);

    After opening my host, I received three sets of data from the application server. Since the first request contained the TERM TYPE request, I sent the reply that I was an 'xterm' with the sendOpt function:

    $t->open($host); recv($t, $data, 1024, 0); $nto->answerTelnetOpts($t, $data); $nto->sendOpt($t, 'SB', 24, 'IS', 'xterm'); recv($t, $data, 1024, 0); $nto->answerTelnetOpts($t, $data); recv($t, $data, 1024, 0); $nto->answerTelnetOpts($t, $data);

    And then I went about my business as usual with Net::Telnet:

    $t->telnetmode(1); ($prematch, $match) = $t->waitfor('/login:/');
      Woo, I'm impressed. I would have thought that you could use the sub callback as you had before, with this method, and just get NTO to send the "xterm" reply for you.. But yours apparently works too. Since it doesnt really care in which order it gets which options replied to, and if you get a host that doesnt send the TTERM option, itll just ignore your reply.

      Would you mind trying with callback as well? Then I'll add this to the NTO docs, thanks!

      C.