At times I find the need to test that the tacacs port 49 is open.
The code below works but is painfully slow because I have to wait on the timeouts.
Examples of possible responds
router1#telnet 10.11.20.14 49
Trying 206.112.204.140, 49 ... Open
[Connection to 206.112.204.140 closed by foreign host]
route1#telnet 10.11.19.14 49
Trying 206.112.196.84, 49 ...
% Connection timed out; remote host not responding
End Examples
I would like to capture and act on the "Trying" lines
... Open = tacacs port good
... = tacacs port bad
end remote telent
end local telnet
But I dont know how to tell expect how to grab those responses from the router. Help would be much appreciated.
The entire code is given below.
while { [gets $ifil host] >=0 } {
#
set timeout 600
spawn telnet $host
expect ":"
send "myusername\n"
expect ":"
send "mypassword\n"
expect ">"
send "en\n"
expect ":"
send "mypassword2\n"
expect "#"
sleep 3
send "telnet 10.11.19.14 49\n"
expect {
{Connection to} {
puts "$host tacacs ok"
}
{Connection timed out} {
puts "$host tacacs nok"
}
}