Python doc モジュールの telnet スクリプトを使用していますhttp://docs.python.org/library/telnetlib.html
出力に空白行がない場合、スクリプトは正常に動作します。
ただし、telnet ソケットは、空白行に遭遇すると閉じます (スクリプトは終了します)。
出力は次のとおりです。 line1
(空行)
line2
import getpass
import sys
import telnetlib
HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("ls\n")
tn.write("exit\n")
print tn.read_all()