Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- #_*_coding: utf8_*_
- #__author__ = 'Taxxer'
- import paramiko, time, datetime, os
- login = 'adminX'
- passw = 'adminX0'
- port = 22
- comm = 'put [system resource get uptime ]'
- file = open('host.txt')
- need = file.read().rstrip().split('\n')
- times=datetime.datetime.now()
- ccount=0
- ecount=0
- print("Hello, I'm ssh paramiko\n if you load ip addresses in file\n let's begin")
- print('')
- #print('Enter login:')
- #login=str(input())
- #print('Enter Password:')
- #passw=str(input())
- #print('Enter Port:')
- #port=int(input())
- #print('Enter Command:')
- #comm=str(input())
- try:
- y = os.mkdir('C:\\Users\\lixdv.ISKRA\\PycharmProjects\\untitled\\New_Work\zx\\%s\\' % times.strftime("%d-%m-%Y %I_%M%p"))
- except:
- print('Папка с файлами уже существует %s, удалите.' % times.strftime("%d-%m-%Y %I_%M%p"))
- print('Завершаю выполнение просцесса.')
- quit()
- else:
- x = ('C:\\Users\\lixdv.ISKRA\\PycharmProjects\\untitled\\New_Work\zx\\%s\\' % times.strftime("%d-%m-%Y %I_%M%p"))
- ip=[]
- for i in need:
- print(i+'*'*10)
- ip.append(i)
- try:
- client = paramiko.SSHClient()
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(hostname=i, username=login, password=passw, port=port, timeout=2)
- print('connect', )
- ccount+=1
- except:
- print('except')
- with open(x+'\errors.txt', 'a') as f:
- read = f.write(i+'\n')
- ecount+=1
- else:
- stdin, stdout, stderr = client.exec_command(comm)
- print('else')
- data = stdout.read().decode('utf-8') + stderr.read().decode('utf-8')
- with open(x+i+'.txt', 'w') as f:
- read = f.write(data)
- with open(x + '\command.txt', 'a') as f:
- read = f.write(comm)
- print("I'm Done!")
- print('')
- print('Успешных подключений: '+str(ccount))
- print('Внесено в errors: '+str(ecount))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement