Evil_TTL> show | s

SSH with Python

Category:Automation -> Python

Prerequisites:

  1. Python Programming Language
  2. Paramiko Module

For more information on how to install Python and define Environment Variables for ‘pip’ to work, refer to How to Install Python

To install Paramiko, which is an SSH client for Python, open ‘cmd’ and type:

pip install paramiko 

Basic SSH connectivity with Python to execute SINGLE command

Set up your router. Assumption is that you should know how to do it already.

In file ssh.py:

import paramiko 

host 
'192.168.1.66'
user 'cisco'
secret 'cisco'
port 22

ssh 
paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #Set policy to use when connecting to servers without a known host key
ssh.connect(hostname=hostusername=userpassword=secretport=port

After executing this script, you will be able to see second VTY session created by Paramico on the Router itself:

R1#sh user
    
Line       User       Host(s)              Idle       Location
*514 vty 0     cisco      idle                 00:00:00 192.168.1.110
 515 vty 1     cisco      idle                 00
:00:05 192.168.1.110 

 

By privilege15