Wednesday, 13 September 2017

Python for network engineer :- SSH to Cisco router using Python2.7

Below script can be used to access the device using SSH and capture show ip int brief command output.

import paramiko  #--<< import Paramiko library
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # --<< to add host key
ssh.connect('192.168.1.100', port=22, username='test', password='test')--<< Device IP address, ssh port , username and password of the device)
stdin,stdout,stderr=ssh.exec_command('show ip int brief')
output=stdout.readlines()
type(output)
print '\n'.join(output)


Output:-

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet0/0            192.168.1.100   YES manual up                    up      

FastEthernet1/0            unassigned      YES unset  administratively down down    

FastEthernet1/1            unassigned      YES unset  administratively down down    

FastEthernet2/0            unassigned      YES unset  administratively down down    

FastEthernet2/1            unassigned      YES unset  administratively down down    

FastEthernet3/0            unassigned      YES unset  administratively down down    

FastEthernet3/1            unassigned      YES unset  administratively down down    

>>> 

No comments:

Post a Comment