Telnet
Billy Ng
evebill8 at hotmail.com
Thu Mar 21 17:24:09 EST 2002
Thanks! "\r\n" is the key. It works after I added into the write().
functon
Okay, now I have 2 more questions.
1) How can I save the returned data into a list? I tried to use the
read_all() function, but it just stops there.
tn.read_until("ending line")
lines = []
lines = tn.read_all()
2) I was also trying to do this,
tn.read_until("beginnig line to grap")
lines = []
lines = tn.read_until("ending line")
for line in lines
print line
But it prints one character in each line
Any input will helps,. thanks!
Billy Ng
"Chris Liechti" <cliechti at gmx.net> wrote in message
news:Xns91D8D7543A398cliechtigmxnet at 62.2.16.82...
> "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