Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import netmiko
- import getpass
- # global variables
- _platform = 'juniper'
- _username = raw_input("Username?:")
- _password = getpass.getpass(prompt="Password?:")
- _port = 22
- _data = open("hosts.txt")
- def send_command(command, ip):
- try:
- dev_ssh = netmiko.ConnectHandler(
- device_type=_platform,
- ip=ip,
- username=_username,
- password=_password,
- port=_port,
- secret=_password,
- )
- output = dev_ssh.send_command(command).split()
- with open(ip + ' configthreadmaybe.txt','w+') as file:
- for line in output:
- file.write(line)
- print('{} -- Complete'.format(ip))
- except:
- pass
- def main():
- all_devices = [ip for ip in _data]
- thread_list = [threading.Thread(target=send_command, args=('show interfaces descriptions',ip,)) for ip in all_devices]
- for thread in thread_list:
- thread.start()
- for thread in thread_list:
- thread.join()
- if __name__ == '__main__':
- main()
- print('Complete')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement