• python脚本


    # Read from a list of hostnames to connect to
    hosts = open('hosts.txt','r')
    hosts = hosts.read()
    hosts = hosts.strip().splitlines()
    
    # Get UserName and password from input
    userName = input('Username: ')
    passWord = getpass.getpass()
    
    # Loop to process hosts in hosts.txt file
    for host in hosts:
    	# Define device type and connection attributes
    	cisco = {
    		'device_type': 'cisco_ios',
    		'ip': host,
    		'username': userName,
    		'password': passWord),
    	}
    	
    	# Netmiko SSH Connection Handler
    	net_connect = ConnectHandler(**cisco)
    
    	#open file to write command output
    	file = open(host + '_output.txt', 'w')
    	
    	# Execute commands
    
    	output = net_connect.send_command('show run')
    	
    	# Print output to console screen
    	print('-------------- Output from ' + host + '------------------')
    	print(output)
    	print()
    	print()
    	
    	# Write output to file above
    	file.write(output)
    	file.close()
    
  • 相关阅读:
    数据库 连接(join)
    Linux top
    Game2048
    黑豆白豆问题
    1000个苹果10箱
    Jconsole
    八数码 Java实现
    两数之和
    磁盘调度算法
    常见应用网络层次
  • 原文地址:https://www.cnblogs.com/zhaoyong631/p/13364994.html
Copyright © 2020-2023  润新知