Pexpect telnet into one device and then from there to another


 
Thread Tools Search this Thread
Top Forums Programming Pexpect telnet into one device and then from there to another
# 1  
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

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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
Login or Register to Ask a Question