1

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?

Use of this system by unauthorized persons or in an unauthorized manner is prohibited.



******************************************************************************

*         Banner              *

******************************************************************************

    1          option 1

    2          option 2

    16        option 16

    X          Exec Prompt

    W          Who is connected

    R          Resume the last connection

    C          Close the last connection

    Z          Logout

    32         Available

Enter Selection: X

switch1>

Thanks

sunder
  • 1,803
  • 4
  • 29
  • 50

1 Answers1

2

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.
Simone Zabberoni
  • 2,024
  • 1
  • 10
  • 15