A python telnet entry level question

Mark nospam at nospam.com
Wed Apr 28 10:12:57 EDT 2004


"Andrew Jones" <ajones at sgi.com> wrote in message
news:c67vo4$go4gt$1 at fido.engr.sgi.com...
> It might be getting stuck on the Password part.
>
> Try this:
>
> tn.read_until("Password: ", 1)
>
>
> Ethereal can be very helpful. Use it to see what is happening on the
> wire. It has a "follow TCP stream" function. Obviously this will not
> work for telneting to localhost so you will need to telnet to a remote
host.

I just discovered telnetlib yesterday and found "set_debuglevel" to be very
useful to figure out what to read_until.

-Mark

>
> Good luck.
> Andy
>
> Jinming Xu wrote:
> > 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