473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

pexpect telnet login from one device to another

20
I am trying to use pexpect to telnet to a device and then subsequently telnet from that device to another device and then output the result of a command on the second 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

Expand|Select|Wrap|Line Numbers
  1. import pexpect
  2.  
  3. child = pexpect.spawn('telnet 192.168.2.45');
  4.  
  5. child.expect('assword:');
  6. child.sendline('getin');
  7.  
  8. child.expect('AS-C5350-02>');
  9. child.sendline('telnet 192.168.1.2'); 
  10. child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
  11. child.sendline('cisco'); 
  12. child.expect('ipipgw01>'); 
  13. child.sendline('sh clock');
  14. child.sendline('exit');
  15.  
  16. child.expect(pexpect.EOF);
  17.  
  18. print child.before;
  19.  
Here is the error i keep getting

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "expect_telnetback.py", line 14, in <module>
  3.     child.expect('\nTrying 192.168.1.2 ... Open\n\n\nUser Access Verification\n\nPassword:');
  4.   File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1311, in expect
  5.     return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
  6.   File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1325, in expect_list
  7.     return self.expect_loop(searcher_re(pattern_list), timeout, searchwindowsize)
  8.   File "/usr/lib/python2.6/dist-packages/pexpect.py", line 1409, in expect_loop
  9.     raise TIMEOUT (str(e) + '\n' + str(self))
  10. pexpect.TIMEOUT: Timeout exceeded in read_nonblocking().
  11. <pexpect.spawn object at 0xb7752a2c>
  12. version: 2.3 ($Revision: 399 $)
  13. command: /usr/bin/telnet
  14. args: ['/usr/bin/telnet', '192.168.2.45']
  15. searcher: searcher_re:
  16.     0: re.compile("
  17. Trying 196.192.7.14 ... Open
  18.  
  19.  
  20. User Access Verification
  21.  
  22. Password:")
  23. buffer (last 100 chars): telnet 192.168.1.2
  24. Trying 192.168.1.2 ... Open
  25.  
  26.  
  27. User Access Verification
  28.  
  29. Password: 
  30. before (last 100 chars): telnet 192.168.1.2
  31. Trying 192.168.1.2 ... Open
  32.  
  33.  
  34. User Access Verification
  35.  
  36. Password: 
  37. after: <class 'pexpect.TIMEOUT'>
  38. match: None
  39. match_index: None
  40. exitstatus: None
  41. flag_eof: False
  42. pid: 26275
  43. child_fd: 3
  44. closed: False
  45. timeout: 30
  46. delimiter: <class 'pexpect.EOF'>
  47. logfile: None
  48. logfile_read: None
  49. logfile_send: None
  50. maxread: 2000
  51. ignorecase: False
  52. searchwindowsize: None
  53. delaybeforesend: 0.05
  54. delayafterclose: 0.1
  55. delayafterterminate: 0.1
  56.  
  57.  
Feb 4 '13 #1
0 2103

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tom Lynn | last post by:
I'm considering using a PHP command line script to retrieve reports from a Linux system. My only source for the report is via telnet. Has anybody here used fsockopen() to interactively script a...
3
by: Adam Flott | last post by:
I'm having some difficulty getting the expect function of telnetlib to capture some data that gets returned from a telnet connection. Python's telnet debug reports this: recv...
2
by: Stephen Yip via .NET 247 | last post by:
Dear All, I would like to perform a simple task by program (VB.Net or VC#.Net). When a user logins the windows and try to run my program, how can I use his login information (username and...
3
by: Bob | last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After succesfull validayion of user I want to open a first form and close the loging form that was used, If I write If...
1
by: james2 | last post by:
I am trying to write a perl script that will do remote machine. I have done user loging using simple command; $telnet->login('test', 'test123'); But now I want to do root login or superuser...
1
by: perlxyo999 | last post by:
Hi , I have a problem doing manipulation (like split) in string comeing back from telnet commnd : $HOST = 'xxx'; $USER = 'yyy20'; $PASS = 'yyy-pass'; #$telnet = Net::Telnet->new($HOST);...
1
LeoTD
by: LeoTD | last post by:
Hi all, I have a web site ex: www.myweb.com, when i login in this site, cookies is written. This site have a link to www.owner.com. Both of site use 1 login information from LDAP. Can I use...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
17
by: ravimath | last post by:
Dear all, I have written following script to loin to router bu it is showing error. #!c:\Perl\bin; use strict; use warnings; my $hostname = 'REMOVED FOR YOUR PROTECTION'; my $password =...
2
by: manuitpro | last post by:
Hi, I have implemented a php script by which i can login to a router using fsockopen(), and i can run any cisco commands. But i have requiremnt login to a remote from from a central router for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.