Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Parsing Net::Telnet Console Ouput

by insensate (Hermit)
on Oct 08, 2002 at 21:34 UTC ( [id://203764]=perlquestion: print w/replies, xml ) Need Help??

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

I've connected to a console server and issued commands to gather the information I need using Net::Telnet. However...the interface that formats fields for display in the console returns what looks like garbage from my perspective (the ? are leftward pointing arrows):
Enter?[C TN:?[1;25H (or?[C press?[C RETURN?[C to?[C do?[C an?[C AD-HOC?[C Query)?[1;24H ?[1;14H
Is this output familiar to anyone? If so...is there a module available to parse it? Or is there a way to more coherently recieve the data from the telnet server?
Thanks, Jason

Replies are listed 'Best First'.
Re: Parsing Net::Telnet Console Ouput
by jlongino (Parson) on Oct 08, 2002 at 21:51 UTC
    What you're getting back is the raw data including terminal emulation escape sequences. To get plain text, telnet to the account and modify your $term setting. You may want something simple like "tty". Exactly how you set this environment variable will vary depending on what shell you use. E.g., on my Solaris 8 unix box (running tcsh, similar to csh), I would issue the command: set term=tty

    Note that if you do this (you might even want to change your shell initialization file permanently to reflect this) you may have to go back and twiddle with your expected prompt string. Also, instead of using terminal type "tty", you may want to set it to be the same or compatible with the telnet client you are using.

    --Jim

Re: Parsing Net::Telnet Console Ouput
by insensate (Hermit) on Oct 21, 2002 at 19:00 UTC
    Update: The telnet server application was an informix database and wouldn't support tty. I finally was able to craft the solution I wanted by passing the terminal output to HTML::FromANSI. A really slick module that parses the terminal data and escape sequences into HTML.
    use HTML::FromANSI qw|%Options ansi2html|; $t=new Net::Telnet(Binmode=>1,Timeout =>20, Prompt=>'/\?/'); $t->dump_log("telnet.log"); $t->open("host"); $t->login("user","pword"); ###fetch terminal output here...store in $output $t->close(); ###HTML::FromANSI portion $Options{fill_cols} = 1; #preserve spacing print "<HTML><HEAD><TITLE>Results</TITLE></HEAD><BODY>". ansi2html("$output"). "</BODY></HTML>";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found