Reputation: 13
I want to read until for Multiple Prompts in the TelnetLib Library.
tn.read_until(b"login: ")
Thats what im currently using but as you can see it only waits for "login:" Prompt.
Now in perl the solution for me was:
$t->waitfor('/[:>%\$#]/');
Any way i can convert the code?
Upvotes: 1
Views: 2513
Reputation: 14814
From https://docs.python.org/2/library/telnetlib.html#telnetlib.Telnet.expect:
Telnet.expect(list[, timeout])
Read until one from a list of a regular expressions matches.
The first argument is a list of regular expressions, either compiled (regex objects) or uncompiled (strings). The optional second argument is a timeout, in seconds; the default is to block indefinitely.
Return a tuple of three items: the index in the list of the first regular expression that matches; the match object returned; and the text read up till and including the match.
If end of file is found and no text was read, raise EOFError. Otherwise, when nothing matches, return (-1, None, text) where text is the text received so far (may be the empty string if a timeout happened).
If a regular expression ends with a greedy match (such as .*) or if more than one expression can match the same input, the results are non-deterministic, and may depend on the I/O timing.
Upvotes: 2