import getpass import paramiko import time import sys
def disable_paging(remote_conn): '''Disable paging on a Cisco router'''
remote_conn.send("terminal length 0\n")
time.sleep(1)
output = remote_conn.recv(1000)
return output
if name == 'main':
ip = input("Please enter the IP address:") username= input("Please enter username of network device:") # password= input("Please enter password of network device:") password= getpass.getpass("Please enter password of network device:")
remote_conn_pre=paramiko.SSHClient() remote_conn_pre
remote_conn_pre.set_missing_host_key_policy( paramiko.AutoAddPolicy())
remote_conn_pre.connect(ip, username=username, password=password, look_for_keys=False, allow_agent=False) print ("SSH connection established to %s" % ip)
remote_conn = remote_conn_pre.invoke_shell() print ("Interactive SSH session established")
output = remote_conn.recv(1000)
print (output)
sys.stdout.flush()
disable_paging(remote_conn)
remote_conn.send("\n") remote_conn.send("enable terminal") password= getpass.getpass("Please enter enable terminal password of network device:")
remote_conn.send("\n") remote_conn.send("show running-config\r\n")
time.sleep(2)
output = remote_conn.recv(65534)
print (output)
sys.stdout.flush()
with open('running-config.txt', 'wb') as f_out: f_out.write(output)
print ('running-config')
remote_conn.send("\n") remote_conn.send("show startup-config\r\n")
time.sleep(2)
output = remote_conn.recv(65534)
print (output)
sys.stdout.flush()
with open('startup-config.txt', 'wb') as f_out: f_out.write(output)
print ('startup-config')
remote_conn.send("\n") remote_conn.send("show version\r\n")
time.sleep(2)
output = remote_conn.recv(65534)
print (output)
sys.stdout.flush()
with open('show-version.txt', 'wb') as f_out: f_out.write(output)
print ('show version')
remote_conn.send("\n") remote_conn.send("show run | incl enable secret\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show startup-config\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | beg banner\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl tcp-small-servers\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl udp-small-servers\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl service pad\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl service tcp\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl finger\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl http secure\r\n")
time.sleep(2)
print (output) sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl boot network\r\n")
time.sleep(2)
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl service config\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show ntp associations\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show vlan-switch\r\n")
time.sleep(2)
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show interfaces trunk\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show interfaces\r\n")
time.sleep(2)
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl logging\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | beg vty 0\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show line con 0 | begin Timeout\r\n")
time.sleep(2)
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show ip ssh\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show snmp\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show snmp community\r\n")
time.sleep(2)
with open('output.txt', 'wb') as f_out: f_out.write(output)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show access-lists\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl dot1x\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show run | incl dot1x\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show interface pruning\r\n")
time.sleep(2)
print (output)
sys.stdout.flush()
remote_conn.send("\n") remote_conn.send("show snmp group\r\n")
time.sleep(2)
output = remote_conn.recv(65534) print (output) sys.stdout.flush()
with open('output.txt', 'wb') as f_out: f_out.write(output)
print ('output')
sys.stdout.flush()
#close (f_out) print ("Script finished, closing SSH connection") remote_conn.close()