A python telnet entry level question

Jinming Xu cybermanxu at hotmail.com
Thu Apr 22 12:02:07 EDT 2004


Eddie,

Thank you very much for your answer.  I checked the prompt of the server, 
findint its prompt is "login:", in stead of "login: ". That's all the 
problem I have.


Thanks again. Have a nice day!

Jinming


>From: eddie at holyrood.ed.ac.uk (Eddie Corns)
>To: python-list at python.org
>Subject: Re: A python telnet entry level question
>Date: Thu, 22 Apr 2004 10:11:23 +0000 (UTC)
>
>"Jinming Xu" <cybermanxu at hotmail.com> writes:
>
> >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()
>
>You are maybe being too specific in what you match for.  At least one of my
>machines prompts:
>
>   Pasword for <username>:
>
>rather than just "Password: ".  I tend to match things like
>
>"ogin"  (in case of Login vs login)
>"assword" (will this get filtered out by censoring s/w?)
>
>Eddie
>--
>http://mail.python.org/mailman/listinfo/python-list

_________________________________________________________________
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