telnet
Billy Ng
kwokng at earthlink.net
Thu May 2 14:21:17 EDT 2002
Thanks, Eddie! It works. But how can I check if it times out if I put the
second arg to the tn.expect() method? What I notice is it just stops when
it times out.
Thanks!
Billy Ng
"Eddie Corns" <eddie at holyrood.ed.ac.uk> wrote in message
news:aaohqk$p2p$1 at scotsman.ed.ac.uk...
> "Billy Ng" <kwokng at earthlink.net> writes:
>
> >Hi folks,
>
> >I am writing a python app that uses the Telnet object to connect to the
> >server. Here is the code,
>
> >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()
>
> >Thanks!
>
> >Billy Ng
>
> I think you need to use tn.expect here. I've not tried it yet but I guess
it
> goes along the lines of:
>
> resp = tn.expect (["password","id again"])
> if resp[0] == 0: # wants a password
> tn.write (pass)
> else: # oops
> ...
>
> In reality you'd want to specify the strings a bit more carefully.
>
> Eddie
>
More information about the Python-list
mailing list