Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Out of control in Net::Telnet

by Lonny (Novice)
on Nov 24, 2002 at 18:54 UTC ( [id://215529]=perlquestion: print w/replies, xml ) Need Help??

Lonny has asked for the wisdom of the Perl Monks concerning the following question:

Oh wise monks, stop the voices in my head, I beg of you.
My problem :
Establish a telnet connection to a device's alarming port. Change the mode of the alarming connection from 'GUI' to clear text (i.e. no control characters creating garbage in the data stream). This is done by pressing F-11 in a simple telnet session. According to xev, F-11 = "\0xffc8". Now, how does one pass this via perl using Net::Telnet?

Solution (or beginnings thereof):
sub openport{ my ($name,$ip,$port)= @_ ; print "Connecting to $name @ $ip:$port " if $debug > 1; my $nameport = $name.$port; $$nameport = new Net::Telnet (Timeout => 120); $$nameport->errmode("return"); $$nameport->open(Host => $ip, Port => $port); if (($error = $$nameport->errmsg) ne ""){ return $error; } else { return "OK"; # Now we send F-11 change the session to clear text. $$nameport->cmd("[Here's the problem]"); } }


$$nameport->cmd needs to emmulate the F-11 keystroke. Any input would be greatly appreciated.

Thank you.

Replies are listed 'Best First'.
Re: Out of control in Net::Telnet
by pg (Canon) on Nov 24, 2002 at 19:45 UTC
    Try sprintf, say:
    $cmd = sprintf("%c%c", 0xff, 0xc8);
      Don't need sprintf when the same thing can be accomplished with a string literal. "\xff\xc8"
      That almost fixed it. Result was it definitely changed the interface but still getting of the gui control chars. I'm going to play with some ENV vars and see if I can finish the clean up.

      Thank you so much for the pointer!!!
Re: Out of control in Net::Telnet
by dakkar (Hermit) on Nov 25, 2002 at 14:08 UTC

    I think that you are going to have to find a bit more about the terminal settings of your device.

    What xev tells you is the X11 keysym of F11. It also tells you the keycode (95).

    In my rxvt, if I say:

    $ cat >a

    and press F11, the resulting file is:

    $ hexdump a 0000000 5b1b 3332

    In general, what codes to send to a terminal to emulate a keystroke (usually apart from the trivial ones) depends on the type of terminal.

    If you know the terminal type, you can use Term::Cap:

    use Term::Cap; $terminal = Tgetent Term::Cap { TERM => 'vt100' }; $f11=$terminal->Tputs('F1',1);

    replacing vt100 with the appropriate terminal type.

    Note: the termcap(5) manpage says that the capability called F1 is "The string sent by function key f11". Alternatively, you can try FB.

    -- 
            dakkar - Mobilis in mobile
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-18 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found