A python telnet entry level question

Jinming Xu cybermanxu at hotmail.com
Wed Apr 21 22:14:48 EDT 2004


Hello Everyone,

I am trying to write a python script to telnet to a server and then do 
something there. As the first step, I practiced the python example in Lib 
Reference 11.13.2. But I am finding the script stops after I supplied the 
password.  Does anyone know why?


Thanks in advance!

Jinming Xu

PS: Here is the script:

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()

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE 
download! http://toolbar.msn.com/go/onm00200413ave/direct/01/





More information about the Python-list mailing list