Sponsored Content
Top Forums Programming Pexpect telnet into one device and then from there to another Post 302766395 by kaf3773 on Monday 4th of February 2013 04:16:06 PM
Old 02-04-2013
Pexpect telnet into one device and then from there to another

I am trying to use pexpect to telnet to a device and then subsequently
telnet from that device to another device but i am unable to. Here is the
script i wrote and the error i am getting

I will appreciate help very much. Thanks

Code:
import pexpect

child = pexpect.spawn('telnet 192.168.2.45');

child.expect('assword:');
child.sendline('getin');

child.expect('AS-C5350-02>');
child.sendline('telnet 192.168.1.2'); 
child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
child.sendline('cisco'); 
child.expect('ipipgw01>'); 
child.sendline('sh clock');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;

This is the error i keep getting

Code:
Traceback (most recent call last):
  File "expect_telnetback.py", line 14, in <module>
    child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
    return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
    return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
    raise TIMEOUT (str(e) + '\n' + str(self))
pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
<pexpect.spawn object at 0xb7752a2c>
version: 2.3 ($Revision: 399 $)
command: /usr/bin/telnet
args: ['/usr/bin/telnet', '192.168.2.45']
searcher: searcher_re:
    0: re.compile("
Trying 196.192.7.14 ... Open


User Access Verification

Password:")
buffer (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
before (last 100 chars): telnet 192.168.1.2
Trying 192.168.1.2 ... Open


User Access Verification

Password: 
after: <class 'pexpect.TIMEOUT'>
match: None
match_index: None
exitstatus: None
flag_eof: False
pid: 26275
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1

 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remote monitoring of device by telnet

There is programm of monitoring by telnet. The main body of script is mkfifo pipe0 telnet $host $port < pipe0 > file0 & then after analizing of file0 printf "commands\r" > pipe0 This programm worked till then I kill pipe0 during working of programm. Now this script dont... (1 Reply)
Discussion started by: ILA
1 Replies

2. AIX

Telnet disconnects on handheld device AIX

I have intermec handheld device which is connecting to AIX Server on port 12431 or whatever. ( oracle application ) The handheld device connects for few seconds and then disconnects from the AIX server. Once it disconnects the handheld device automatically switches off. Are there any... (2 Replies)
Discussion started by: filosophizer
2 Replies

3. Ubuntu

Ubuntu 9.04 Serial application to telnet to serial device

Hello! I am working on an application which reads environmental instruments which have serial ports. The application requires a serial port to be present to talk to the device (i.e. /dev/ttyS0 ). In some instances the environmental devices will be 100's of yards away from the computer, so a... (5 Replies)
Discussion started by: mvona
5 Replies

4. Red Hat

Unable To Activate Ethernet Network Device in RHEL 5.5 - e100 device eth0 does not seem to be presen

Hi All, Could anyone please help to resolve the below problem. I installed RHEL5.5 in my desktop.But when i try to activate the ethernet connection then it gives me the error. I spent 2 days for the above and go through with several suggestion found by googling. But no luck. ... (0 Replies)
Discussion started by: Tanmoy
0 Replies

5. HP-UX

Failed to open tape device /dev/rmt/0mn:Device busy (errno = 16)

Hi, Unable to make tape backup, please help. /opt/ignite/bin/make_tape_recovery -a /dev/rmt/?mn -I -v -m tar -x inc_entire=vg00 * Creating local directories for configuration files and archive. ======= 04/25/16 16:28:08 IST Started /opt/ignite/bin/make_tape_recovery. (Mon... (4 Replies)
Discussion started by: anuragr
4 Replies

6. Programming

Edit a file using pexpect python

Hi I am damn new to this python scripting I have arrived till getting into the console of a machine using pexpect Now I just wanted to know how to list/edit the contents of a file using pexpect Please help:confused: (0 Replies)
Discussion started by: Priya Amaresh
0 Replies
telnetrc(4)						     Kernel Interfaces Manual						       telnetrc(4)

NAME
telnetrc, .telnetrc - Specifies setup commands for a telnet session SYNOPSIS
$HOME/.telnetrc DESCRIPTION
The .telnetrc file contains the setup information for a telnet session. It is a hidden file in your home directory and must be readable by the user logging in. The file can consist of multiple entries for each remote host to which a user can connect. A remote host entry consists of multiple lines. The first line is the name of a remote host. The subsequent lines must begin with blank spaces, and contain telnet subcommands. These sub- commands are processed as though they were typed in manually. Lines beginning with a number sign (#) are comment lines. See telnet(1) for a complete list of telnet subcommands. To specify subcommands that apply to all systems, create an entry, using the word "DEFAULT" as the system name, and specify the telnet sub- commands in the subsequent lines. EXAMPLES
The following shows a sample .telnetrc file: # Beginning of telnetrc file # Default subcommands that apply to all systems DEFAULT environ undefine USER # First system entry system1 set echo toggle crlf # Second system entry system2 set echo mode line toggle crlf FILES
User-customized telnet startup values. RELATED INFORMATION
Commands: telnet(1). delim off telnetrc(4)
All times are GMT -4. The time now is 12:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy