telnet

Billy Ng kwokng at earthlink.net
Tue Apr 30 21:40:37 EDT 2002


I'm not sure if I know what you mean.  Basically, I want to know how to
write that depends on the read's response.  For example,

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

This example only assumes tn.read_until() will read "Password".  What if the
tn returns something else?  Therefore, I want to check the "Password"
returns before I write password.

Billy Ng

"Chris Liechti" <cliechti at gmx.net> wrote in message
news:Xns9201FD27582Dcliechtigmxnet at 62.2.16.82...
> "Billy Ng" <kwokng at earthlink.net> wrote in
> news:5cFz8.127$ke3.35 at newsread2.prod.itd.earthlink.net:
> > tn = telnetlib.Telnet(host)
> > tn.read_until("Please enter your id")
> > tn.write(userid+"\r\n")
> >
> > From here, tn will return either "Please enter your password" or
> > "Wrong id, please enter your id again".  My question is how can I get
> > the returning string before I do the next tn.write()
>
> can't you go for a newline? often such messages print on a separate line,
> so you can just "readline" and use string methods to find out if it was
> positive.
>
> chris
>
> --
> Chris <cliechti at gmx.net>
>
>





More information about the Python-list mailing list