Reputation: 853
import telnetlib
tn = telnetlib.Telnet(IP)
tn.read_until("abcd login: ") --> This is only to match a particular pattern
Can a generic pattern be included in tn.read_until()
?
Ex: prompt can be "xyz login: " , "abcd login: "
etc
In regular expression, we use re.match('(.*)login: ',prompt)
. But i don't think so, this works in tn.read_until()
because the parameter it expects itself is a pattern. Is there any way to handle it ?
Upvotes: 4
Views: 5173
Reputation: 369094
Telnet.expect
accepts a list of regular expressions:
tn.expect([r"\w+ login: "])
Upvotes: 6