telnetlib

bragib at my-deja.com bragib at my-deja.com
Mon Jul 31 16:50:08 EDT 2000


Maybe you can offer some suggestions on this:
This is a repost as I am still clueless!

 Bragi


 I am trying to telnet from a UNIX box to an NT to get the doskeys. The
NT that I login to runs a
 couple of .bat
 scripts which clear the screen set up some stuff etc.  When I try to do
a read_all() it fails the first
 time with the
 exception:
 Traceback (innermost last):
   File "telnet.py", line 17, in ?
     tn.read_all()
   File "/usr/abaqus60/5-0_copy/source/Python/Lib/telnetlib.py", line
229, in read_all
     self.fill_rawq()
   File "/usr/abaqus60/5-0_copy/source/Python/Lib/telnetlib.py", line
367, in fill_rawq
     buf = self.sock.recv(50)
 socket.error: (131, 'Connection reset by peer')


 That is why I put the first try in a try: except: clause.  The second
time I try to do a read_all() it
 works fine but I
 don't get all the keys I am missing some of the first keys.  I assume
that the first read_all()
 actually did read
 some stuff and then the second read got the rest.

 Can anyone see anything obviously wrong with this.


 Thanks, Bragi

 import sys
 import telnetlib
 HOST = 'shadow'
 USER = 'bragi'
 tn = telnetlib.Telnet()
 tn.open(HOST)
 tn.read_until("login: ")
 tn.write(USER+'\r\n')
 tn.read_until("password: ")
 tn.write('my_password\r\n')
 tn.write('doskey /macros\r\n')
 tn.write('exit\r\n')
 print 'done'
 try:
     all1 = tn.read_all()
 except:
     pass
 all = tn.read_all()
 print all


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list