zoukankan      html  css  js  c++  java
  • 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()
    
  • 相关阅读:
    简单数学问题
    MFC 注册表编程
    Windows多线程端口扫描
    MFC Socket双向通信
    凯撒加密
    单片机滤波
    大数素性检验
    大数加法乘法
    Unsafe Code
    委托
  • 原文地址:https://www.cnblogs.com/zhaoyong631/p/13364994.html
Copyright © 2011-2022 走看看