Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Perl Telnet client not receiving all the data

by jicjoc (Initiate)
on Oct 25, 2013 at 16:50 UTC ( #1059705=perlquestion: print w/ replies, xml ) Need Help??
jicjoc has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, At work i want to query a results server. I have a simple perl telnet module that can log into the server but it stops receiving data after logging in. Waitfor() times out Getline() receives nothing extra Here is my code:
use Net::Telnet (); $host = "x.x.x.x"; $username = "xxx"; $passwd = "xxxxxxx"; $t = new Net::Telnet (Timeout => 10, Dump_Log => "dump.txt", Input_Log => "in.txt", Output_Log => "out.txt", Prompt => '/$/'); $t->open($host); $t->login($username, $passwd); print $t->getline(); $t->waitfor('/Select Option : ?$/i'); $t->print("1");
Here is my dumpfile
< 0x00000: ff fb 01 ff fb 03 .. > 0x00000: ff fd 01 ff fd 03 .. < 0x00000: 0d 0a 0d ... < 0x00000: 0a 57 65 6c 63 6f 6d 65 20 74 6f 20 4f 70 65 6e .Welcom +e to Open < 0x00010: 56 4d 53 20 41 6c 70 68 61 20 76 65 72 73 69 6f VMS Alp +ha versio < 0x00020: 6e 20 56 37 2e 33 2d 31 20 20 0d 0a 0d 0a 0d 55 n V7.3- +1 .....U < 0x00030: 73 65 72 6e 61 6d 65 3a 20 sername +: > 0x00000: 69 63 75 0d 0a icu.. < 0x00000: 69 i < 0x00000: 63 75 0d 0a 0d 50 61 73 73 77 6f 72 64 3a 20 cu...Pa +ssword: > 0x00000: 69 63 75 31 32 33 34 0d 0a icu1234 +.. < 0x00000: 0d 0a 20 20 20 57 65 6c 63 6f 6d 65 20 74 6f 20 .. We +lcome to < 0x00010: 4f 70 65 6e 56 4d 53 20 28 54 4d 29 20 41 6c 70 OpenVMS + (TM) Alp < 0x00020: 68 61 20 4f 70 65 72 61 74 69 6e 67 20 53 79 73 ha Oper +ating Sys < 0x00030: 74 65 6d 2c 20 56 65 72 73 69 6f 6e 20 56 37 2e tem. Ve +rsion V7. < 0x00040: 33 2d 31 20 6f 6e 20 6e 6f 64 65 20 52 47 4c 41 3-1 on +node RGLA < 0x00050: 42 32 0d 0a 0d B2... < 0x00000: 20 20 20 20 4c 61 73 74 20 69 6e 74 65 72 61 63 Las +t interac < 0x00010: 74 69 76 65 20 6c 6f 67 69 6e 20 6f 6e 20 46 72 tive lo +gin on Fr < 0x00020: 69 64 61 79 2c 20 32 35 2d 4f 43 54 2d 32 30 31 iday. 2 +5-OCT-201 < 0x00030: 33 20 31 37 3a 33 37 3a 30 37 2e 32 35 0d 1b 5b 3 17:37 +:07.25..[ < 0x00040: 63 c < 0x00000: 1b 5c 1b 5a .\.Z < 0x00000: 1b 5b 30 63 .[0c
This is what i see when i just manually enter a telnet session
Welcome to OpenVMS Alpha version V7.3-1 Username: icu Password: Welcome to OpenVMS (TM) Alpha Operating System, Version V7.3-1 on n +ode RGLAB2 Last interactive login on Friday, 25-OCT-2013 17:44:22.40 1 A Live APEX System 2 T Training APEX System 3 S Old Biochemistry Data (up to 9th May 1999)T 4 P Change Password 5 Q Quit/Logout Select Option :
Im guessing its a prompt issue. But ive no idea what my prompt should be. Ive tried switching telnetmode, binmode but no luck Any ideas? Thank you...

Comment on Perl Telnet client not receiving all the data
Select or Download Code
Re: Perl Telnet client not receiving all the data
by keszler (Priest) on Oct 25, 2013 at 17:00 UTC
    Net::Telnet's prompt wants a regex. For this first prompt after login it looks like '/Option :/' would work. You may need to change it later.
Re: Perl Telnet client not receiving all the data
by dasgar (Deacon) on Oct 25, 2013 at 18:41 UTC

    Just to expand on keszler's response.

    Here how I would approach this. First, manually run a telnet client and step through everything that you want your script to do. Make notes of what commands you are issuing and what text is being shown that lets you know that the telnet server is ready for the next command.

    Next, change your 'prompt' argument for the Net::Telnet's new method call to be /Option :/ (as keszler suggested) or /Select Option :/. Then when you issue a command to the telnet server, you can use the 'cmd' method. If you know what the next prompt looks like and it's different than what is specified in the 'new' method when you opened the connection, you can tell the 'cmd' method to use a different regex value for prompt. (i.e. my $resp = $t->cmd(String => '4', Prompt => 'Current Password:');)

    Also, based on the posted content of your dumpfile, I think that you do want to set 'binmode' to 1.

Re: Perl Telnet client not receiving all the data
by ig (Vicar) on Oct 25, 2013 at 21:01 UTC

    It looks to me like the server is sending a VT100 query device code command to the 'terminal' (your telnet client, when you run your script). It is probably then waiting to receive your device code. Since you don't send your device code, it doesn't continue to send the menu and prompt.

    You probably have a timeout because your script is waiting for the server to send data and the server is waiting for your script to send data. It's good that at least one of them timeout.

    You should read up on VT100 terminal. The first source I found with the 'query device code' sequence was http://www.termsys.demon.co.uk/vtansi.htm, but there are many.

      Thank you guys for the help Changing my prompt to a variant of *option* wont help as i am not receiving that data. The suggestion re VT100 sounds most promising. I dont fully understand it, but this is exactly whats happening. my telnet client just sits there waiting for some data. It could be this. I'll invetigate! Thank you Any more experts on VT100, and whether this could be the problem?
      Well spotted! Net::Telnet suggests:
      Usually you want the remote TERM environment variable to be set to something like "dumb" so you don't read escape sequences meant to be interpreted by a display terminal.
      However, here the server requests neither terminal type, nor environment variables, but sends a "\033Z" to query terminal device attributes. A good response to this might be "\033[?6c" ('I am a vt102').

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2014-08-30 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls