python telnet script for openvms host

Ennis Rosamond ennisr at my-deja.com
Wed Dec 27 11:52:36 EST 2000


The script is now working.  Thanks to everyone who responded to my
request for help.  As several people pointed out, the problem was in the
telnet protocol negotiation.  Since I knew virtually nothing about the
nitty gritty of telnet communication, I quickly read a short article on
telnet protocol that I found on the web
(http://www.scit.wlv.ac.uk/~jphb/comms/telnet.htm).  That gave me just
enough information get the script working, though not very elegantly.

Looking at the actual client/host dialog with the aid of the telnetlib
debug option, it appeared that perhaps the host was proposing 'suppress
go ahead', but that acceptance of the option was not being returned by
the client.  (The actual host message was '\377\373\003'.  I haven't yet
found the interpretation of either 377 or 373.)

To fix the script, I added a write call to the host with the message
'\255\253\003', meaning 'do suppress go ahead', following the login
dialog but before scanning for the '$ ' prompt.  I doubt that this a
good general fix-- seems to work here but probably not in other
situations.  The new script is shown below.

#python test script:
import sys, telnetlib
host = 'hostname'
user = 'username\r'
password = 'mypasswd\r'
tn = telnetlib.Telnet(host)
tn.read_until('Username: ')
tn.write(user)
tn.read_until('Password: ')
tn.write(password)
tn.read_until('[c')             #last char of session header message
tn.write('\255\253\003')        #this is the 'fix' command added
tn.read_until('$ ')             #scan for prompt
tn.write('dir\r')               #issue directory command
d = tn.read_until('$ ')         #save results in d
tn.close()
print d

The underlying problem is obviously the lack of option negotiation logic
in the telnetlib module.  (It is on the 'To do' list in the telnetlib
source code.)  Someone with telnet protocol expertise would do the
Python community a valuable service by adding some sophisticated
negotiation code to the module.

(Posted to both Python and OpenVMS discussion groups.)


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list