Please pardon me as I am a very new to any programming language. I have around 25 network devices combination of cisco, juniper, linux etc which i need to remotely access and run some basic cli commands to get the output. Individually SSHing in to the devices will take long time. Can some tell me where to start this basic script?
Asked
Active
Viewed 1,783 times
1
-
You can do that using paramiko (https://github.com/paramiko/paramiko) and `subprocess.run` – Fred Feb 20 '19 at 11:50
2 Answers
1
Try the following:
pip install paramiko
then in your script:
import base64
import paramiko
key = paramiko.RSAKey(data=base64.b64decode(b'AAA...'))
client = paramiko.SSHClient()
client.get_host_keys().add('ssh.example.com', 'ssh-rsa', key)
client.connect('ssh.example.com', username='strongbad', password='thecheat')
def run_command(command)
stdin, stdout, stderr = client.exec_command(command)
for line in stdout:
print('... ' + line.strip('\n'))
return True
run_command('ls')
run_command('cd..')
run_command('apt-get update')
client.close()

alexisdevarennes
- 5,437
- 4
- 24
- 38
1
You can use Netmiko or NAPALM.
These two python libraries support almost all different vendor devices.

alexisdevarennes
- 5,437
- 4
- 24
- 38

Vijay Shetty
- 901
- 10
- 11