Sponsored Content
Top Forums Shell Programming and Scripting Webpage to Telnet via Perl and Expect: Telnet problem? Post 302216695 by jondo on Monday 21st of July 2008 01:12:47 AM
Old 07-21-2008
Webpage to Telnet via Perl and Expect: Telnet problem?

Somewhat long story:

I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage.

This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only accepts one character.
I have sniffed out the traffic and the interaction seems to be valid.
The only clue i think i found is the Telnet negotiation, which I discovered from the telnet debug code:

But when it is spawned by the webpage, there is a difference in this line of code Telnet debug code:
SENT IAC SB NAWS 0 0 (0) 0 0 (0)

The CGI script runs fine when launched from the shell, and shows this code:
SENT IAC SB NAWS 0 80 (80) 0 24 (24)

So...I have given up on everything else, all I can think is that the device, possibly poorly coded and non-compliant, is crapping out on the Web server environment with 0 0 for columns and lines.
If this is the issue, does anyone know a way to force Telnet into standard 80x24 mode, or ignore the negotiation?
This equipment is discontinued and cannot go back to manufacturer to fix their Telnet code.

Thanks
JD
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need 'expect' help, ssh/telnet and trapping

So here is what I am trying to do. I have a large # of switches and routers I am trying to log into. Unfortunately some have ssh only, some have telnet only. and some i have never logged into with ssh. I first want it to SSH, if i have never logged into the box it will ask for adding the ssh key. I... (0 Replies)
Discussion started by: ippy98
0 Replies

2. Infrastructure Monitoring

expect telnet unexpected delays

I must automatically monitor and manage a large number of boxes on our network. I have been using perl/Net::Telnet and expect/telnet and also perl/ssh and expect/ssh to reach the command line of the remote boxes. Scripts are working but slow. (Yes, I do use SNMP also but many boxes do not... (2 Replies)
Discussion started by: kp2a
2 Replies

3. Shell Programming and Scripting

Telnet Expect script question

Hi all, I have written a small expect script which should spawn a telnet session login and execute some commands. #!/usr/bin/expect -f spawn telnet $env(IP) match_max 100000 expect "login:" send -- "******\n" expect -exact "Password:" send -- "****\n" expect "%" Now I have got... (2 Replies)
Discussion started by: stinkefisch
2 Replies

4. Shell Programming and Scripting

telnet commands using expect

Hi All, I am trying to write a expect script to telnet and run a command on a remote host.The command i want to send contains a text value is contained in file.txt in the linux box from where i am running the expect script.I want to pass the contains of file.txt into a variable and call the... (1 Reply)
Discussion started by: pistachio
1 Replies

5. Shell Programming and Scripting

Help needed with expect...(If telnet fails)

Hello I'm working using expect to automate telnet commands...i want to check if telnet fails and in this case...certain message should appear or certain word should be out in a file). Thses are the messages that apeear if telnet fails: Trying 172.16.3.115... telnet: Unable to connect... (0 Replies)
Discussion started by: Hossam_Nox
0 Replies

6. Shell Programming and Scripting

Expect script to automate telnet session

Hi all, I am currently running a daemon which creates a virtual terminal for testing purposes. Essentially, if I were to interact with it manually, this is what I get. john@test1:~$telnet localhost 7777 Trying ::1... Connected to localhost. Escape character is '^]' mip6d> pl eth2... (6 Replies)
Discussion started by: abxccd
6 Replies

7. Shell Programming and Scripting

expect: redirect telnet to file

I've got some expect/tcl scripts. Now i want to add a function that allows to open a telnet connection and redirect the output to a logfile. On the shell/terminal i tried something like: 'telnet 192.168.123.123 12121 > /home/user/logging/log-telnet.log' and the telnet is redirected into the... (2 Replies)
Discussion started by: JaPatton
2 Replies

8. Shell Programming and Scripting

Expect/telnet/testing tacacs on a cisco

At times I find the need to test that the tacacs port 49 is open. The code below works but is painfully slow because I have to wait on the timeouts. Examples of possible responds router1#telnet 10.11.20.14 49 Trying 206.112.204.140, 49 ... Open route1#telnet 10.11.19.14 49 Trying... (1 Reply)
Discussion started by: popeye
1 Replies

9. Shell Programming and Scripting

Calling Expect Script - Telnet

Hi All, I have an Expect script which logs into Cisco switch, performs a show interface command. I want to read a file of ip addresses which will be passed to the expect script. The script to read the file works, the expect script works on it's own but when i call the 'expect' script from the... (12 Replies)
Discussion started by: trinak96
12 Replies

10. Shell Programming and Scripting

expect telnet script execute by cronjob

hi, please help, keep getting this bolded error and look it up and people say its your environment variable though i tried to set it manually in expect..it run fine if i run it manually but once i run it by cronjob it error below..i tried to comment out ip/login info with *.. logfile:: START... (0 Replies)
Discussion started by: cssanangeles
0 Replies
Net::CLI::Interact::Manual::Cookbook(3pm)		User Contributed Perl Documentation		 Net::CLI::Interact::Manual::Cookbook(3pm)

NAME
Net::CLI::Interact::Manual::Cookbook - Miscellaneous recipes Windows Support The library works just fine under native windows (i.e use something like Strawberry Perl - no need for cygwin), for Telnet, Serial and SSH connections. However one additional step is required for you to have success: You must download the "plink.exe" application, and pass its filesystem location in the "app" parameter to "new()". Do not try to use any other Telnet or SSH programs (for instance the Windows bundled "telnet") - they will not work. Here's an example: my $s = Net::CLI::Interact->new( personality => "cisco", transport => "Telnet", (Net::CLI::Interact::Transport::is_win32() ? (app => "$ENV{HOMEPATH}\Desktop\plink.exe") : () ), ); Unix Support The library works fine on most Unix platforms. It will try to use the native "telnet", "ssh" (openssh) and "cu" programs for Telnet, SSH and Serial connections, respectively. If you want to use another application, pass it in the "app" parameter to "new". In some Unix environments there can be zombie child processes left around after running your script. If this happens, set the "reap" option, like so: my $s = Net::CLI::Interact->new( personality => "cisco", transport => "Telnet", connect_options => { reap => 1, }, ); Phrasebook Entries Prompts These are nothing more than named regular expressions: prompt configure match /(config[^)]*)# ?$/ Macros This example waits for the device to ask "[startup-config]?" and then responds with the text "startup-config". macro copy_run_start send copy running-config startup-config match /Destination filename [startup-config]?$/ send startup-config To send instead a press of the Return key (output record separator), use: macro write_mem send copy running-config startup-config match /Destination filename [startup-config]?$/ send '' To instead allow the user to pass in the file name, use a "sprintf" format. macro save_to_file send copy running-config startup-config match /Destination filename [startup-config]?$/ send %s The user must then pass a parameter to the "macro" call, even if it's an empty string: $s->macro('save_to_file', { params => ['file_name'] }); # or $s->macro('save_to_file', { params => [''] }); Continuations These are Macros which start with a match instead of a send: macro more_pages match / --More-- / send ' ' Note that the parameter of the "send" is not sent with a Return character (output record separator) appended. When included in a macro, the continuation can be in-line, like this: macro show_ip_route send show ip route follow / --More-- / with ' ' Running Commands Standalone Commands Simply send the command you wish to execute to the library. If not already done, a connection to the device will be established automatically: $s->cmd('show ip int br'); Normally this matches against a default prompt, which has been discovered automatically, or set by you: $s->set_prompt('user_prompt'); It's also possible to pass in a custom prompt for this command only: $s->cmd('show ip int br', { match => qr/special prompt>$/ }); Composite Macro Commands Call a predefined Macro from the phrasebook using this method: $s->macro('write_mem'); Sometimes the Macro needs parameters: $s->macro('to_priv_exec', { params => ['my_password'] }); You can't really create a Macro on the fly very easily, but with suitable use of "cmd()", "set_prompt()", and the "match" option to "cmd()" it's possible to achieve some simple flexibility. Reconfiguring On-the-Fly Phrasebook It's possible to load a new phrasebook by the following method, which must be passed at least the name of the personality: $s->set_phrasebook({ personality => 'ios' }); You can pass any options which the Phrasebook module itself would take. Prompt The current prompt can be changed by passing the name of the new Prompt as it is known by the phrasebook: $s->set_prompt('name'); If you want to test whether the current prompt matches a diffrent named Prompt from the phrasebook, this method can be used: $s->prompt_looks_like('name'); perl v5.14.2 2012-06-12 Net::CLI::Interact::Manual::Cookbook(3pm)
All times are GMT -4. The time now is 05:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy