import paramiko import time port = 22 username = 'root' password = 'root' sources = 'http://172.20.100.201:8000/iperf3.ipk' subnets = "192.168.16." #objects = [4, 9, 11, 35, 38, 40, 42, 44, 49, 51, 57, 58, 62, 63, 67, 68, 69, 76, 85] objects = [78] #objects = [4, 9, 11, 27, 28, 29, 30, 32, 34, 35, 38, 39, 41, 42, 43, 44, 49, 50, 55, 57, 58, 62, 65, 66, 67, 68, 69, 70, 76, 81, 82, 84] for i in objects: try: # Создаем SSH-клиент client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) hostip = subnets + str(i) # Подключение client.connect(hostname=hostip, port=port, username=username, password=password) print(hostip) # Выполнение команды rem_conn = client.invoke_shell() time.sleep(1) rem_conn.send("wget " + sources + " -P /tmp/\n") time.sleep(2) rem_conn.send("opkg install /tmp/iperf3.ipk\n") time.sleep(5) rem_conn.send("rm /tmp/iperf3.ipk\n") time.sleep(1) rem_conn.send("opkg list-installed | grep iperf\n") time.sleep(1) rem_conn.close() data = rem_conn.recv(1024) print(data.decode()) file = open(hostip + '_IRZ.txt', "a", newline='\n', encoding="utf-8") file.write(data.decode()) file.close() client.close() except TimeoutError: text = 'Нет подключения ' + hostip print(text) file = open('down_no_conn.txt', "a", encoding="utf-8") file.write(text + '\n') file.close()