telnetlib problems

Eddie Corns eddie at holyrood.ed.ac.uk
Wed Mar 1 06:30:34 EST 2006


vercingetorix52 at yahoo.com writes:

>I'm trying to use a python script to access an embedded computer
>running linux and connected via a crossover ethernet cable using the
>following script...

>...and I realize the username and password is not realistic... I'm
>still in "proof of concept" stage here :)

>#########################
>import telnetlib

>tn = telnetlib.Telnet('192.168.100.11')
>tn.read_until('login: ', 5)
>tn.write('user\n')
>tn.read_until('Password: ', 5)
>tn.write('password\n')
>tn.read_until('bash-2.05$ ', 5)
>tn.write('ls\n')
>print tn.read_very_eager()


>As a script, this doesn't work.  However, if I execute the same
>commands interactively, it works fine.  If I insert some time delays as
>follows...

What doesn't work about it?  Have you checked the return value from the
read_until()s to see if they're returning anything sensible? are any of them
timing out?

Anyway, my first guess would be the use of read_very_eager(), it's something
you normally only descend to when you're stuck for something to match on.
Normally you would do another read_until() for the prompt.

Eddie



More information about the Python-list mailing list