Telnet
Chris Liechti
cliechti at gmx.net
Thu Mar 21 15:09:16 EST 2002
"Billy Ng" <evebill8 at hotmail.com> wrote in news:yAqm8.1723$Tk.98335
@newsread1.prod.itd.earthlink.net:
> I am trying to write a telnet client program. Here is the code:
>
> ID = "123445"
> PASSWORD = "333"
>
> try:
> tn = telnetlib.Telnet(<host>)
> tn.read_until("Please enter your id? ")
> tn.write(ID+"\n")
> tn.read_until("Enter your password? ")
> tn.write(PASSWORD+"\n")
> print tn.read_all()
> tn.close()
> except:
> tn.close()
> print 'connection failed'
> tn.close()
>
> It stops after the ID was written. If I use the actual telnet
> client, it returns "Enter your password? " after my ID is
> submitted. why does not tn.read_until() find the "Enter your
> password? " string ? Is there any other way to handle the password
> prompt?
don't write the entire prompt in read_all. insteand use
read_all("word?")
this way you circumwent problems with additional spaces, case atc.
and make sure that your server works with just a "\n", maybe it needs
a "\r\n".
HTH chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list