[geeks] Using Python3 to Telnet to OpenVMS

Mark Benson md.benson at gmail.com
Fri Apr 12 06:08:32 CDT 2013


I am wondering if there are any seasoned Python3 and or OpenVMS hackers out
there can help me.

I am trying to build an automation interface to use telnet to connect, run
a command, return the terminal output, then close the connection.

Thus far I have:

#required libs
import getpass
import telnetlib

#connection spec
HOST = "localhost"
port = 3900

#make connection
tn = telnetlib.Telnet(HOST,port)

#DZV11 requires a CR to start login process, so send one
tn.write(b"\n")

#wait for the Username: prompt
tn.read_until(b"Username: ")

#get a username from the user
user = input("Enter your remote account: ")

#send it to the prompt followed by a CR
tn.write(user.encode('ascii') + b"\n")

#request a passowrd
print("Please enter password.")

#Use getpass to capture the password without echo
password = getpass.getpass()

#wait for the Password: prompt and then enter it followed by CR
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")

#wait for a $ prompt
tn.read_until(b"$")
#DIR command
tn.write(b"DIR\n")

#wait for another $ prompt
tn.read_until(b"$")
#DIR command
tn.write(b"DIR\n")

#wait for another $ prompt
tn.read_until(b"$")
#Log out
tn.write(b"LO\n")

#Print whatever comes back until EOF
print(tn.read_all().decode('ascii'))


Which should, by rights, do something. Thus far it doesn't work, it never
even detects the 'Username: ' string. I don't know enough Python to poke it
really hard although I'm RTFMing it as I go. I am guessing, based on the
fact the skeleton of this script is lifted from the Python 3.2 docs (thus
probably works on generic unix-like systems), that perhaps OpenVMS is
introducing something hairy?

I am connecting via a simh instance with a simulated DZV11 connection. Is
this possible issue?

Confused...

-- 

Mark Benson


More information about the geeks mailing list