I am trying to connect to a Cisco [Cisco IOS Software, C2900 Software (C2900-UNIVERSALK9-M), Version 15.4(3)M3] switch via ansible/python. But I am facing issue because we have enabled a menu when we connect to vty.
Is there any working sample someone can point me towards where I could pass thru this menu and run commands as usual?
JavaScript
x
32
32
1
Use of this system by unauthorized persons or in an unauthorized manner is prohibited.
2
3
4
5
******************************************************************************
6
7
* Banner *
8
9
******************************************************************************
10
11
1 option 1
12
13
2 option 2
14
15
16 option 16
16
17
X Exec Prompt
18
19
W Who is connected
20
21
R Resume the last connection
22
23
C Close the last connection
24
25
Z Logout
26
27
32 Available
28
29
Enter Selection: X
30
31
switch1>
32
Thanks
Advertisement
Answer
You should use expect, or the pexpect python implementation.
A sample workflow:
- open a connection and look for a specific string (ie: “Banner), when found send “X” for the exec prompt
- read the output and look for a string followed by “>”, then send “enable”
- read the output and look for a “Password” prompt, then send “somepassword”
- read the output and look for a string followed by “#”, then send “some command” and so on.