Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Unable to get infor from telnet conection

by iug (Initiate)
on Nov 28, 2019 at 16:04 UTC ( [id://11109373]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I'm newbie to Perl. I'm trying to connect to a device throw telnet. It looks like the connection is done. But I'm unable to get info from it.

It's supposed to be quite fordwarding but no way. I post some kind of code that looks like mi own code.

No login required! I don't know if could be something related to genociation. Also tried with no luck

#!/usr/bin/perl use strict; use warnings; use Net::Telnet(); my $host='xxx.xxx.xxx.xxx'; $t = new Net::Telnet (Timeout => 10, "Prompt" => '/[$%#>] \z/n'); $t->open($host); $t->cmd("command"); while (my $t = $t->getline()) { print "$line" } $t->close(); exit 1;

It gets stack in the "cmd" line. And it returns time-out error Any idea? Thanks a lot

Replies are listed 'Best First'.
Re: Unable to get infor from telnet conection
by roboticus (Chancellor) on Nov 28, 2019 at 16:35 UTC

    iug:

    If it's stuck on the cmd line, I'd expect that the command is waiting for additional input or something similar. Have you read the "Debugging" section of Net::Telnet? It describes a couple functions (input_log() and dump_log()) that you can use to see what's happening so you can figure out the situation. As you've presented it, we don't know what "command" is, what it's doing or why it's hanging.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thanks #roboticus for your quick answer.

      #!/usr/bin/env perl use Net::Telnet; print "reporting end of web server log files:\n"; my($input_log, $output_log, $dump_log); $input_log="./input_log.log"; $output_log="./output_log.log"; $dump_log="./dump_log.log"; $hostname = "127.0.0.1"; $telobj = new Net::Telnet (-host => $hostname ,-port => 23 ,-dump_log => $dump_log ,-input_log => $input_log ,-output_log => $output_log ,-telnetmode => '' ,-prompt => '/^]/' ); $rad = $telobj -> cmd ("get sn"); pop @rad; chomp @rad; print "\n"; $telobj -> close;

      the command gives back a 6 digit string like 123456. de content of the dump_log is > 0x00000: 67 65 74 20 63 6f 6d 6d 73 0d 0a get comms.. < 0x00000: ff fd 03 ff fe 01 ff fb 01 ÿý.ÿþ.ÿû. Any idea?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found