#!/usr/bin/env python3 import paramiko import socket PWD = "DeararbsFr2@" USER = "otantik" HOSTS = ["100.80.255.113", "100.80.113.255"] def tcp_open(host, port=22): s = socket.socket() s.settimeout(5) try: return s.connect_ex((host, port)) == 0 except Exception as e: print("tcp", host, e) return False finally: s.close() def main(): cmd = r""" hostname echo '=== dirs ===' ls -d /var/www/html/otantik_pay /var/www/html/otantik_pay/phpnuxbill /var/www/otantik_pay 2>/dev/null find /var/www /home/otantik -maxdepth 5 -type d \( -iname '*otantik*' -o -iname '*phpnuxbill*' \) 2>/dev/null | head -40 echo '=== provision files ===' find /var/www /home/otantik -maxdepth 8 \( -iname '*provision*' -o -iname '*rsc*' -o -iname '*bootstrap*' -o -iname '*mikrotik*script*' \) 2>/dev/null | head -60 """ for host in HOSTS: print("try", host, "open" if tcp_open(host) else "closed") if not tcp_open(host): continue c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: c.connect(host, username=USER, password=PWD, timeout=15, allow_agent=False, look_for_keys=False) except Exception as e: print("ssh fail", host, e) continue print("ssh ok", host) stdin, stdout, stderr = c.exec_command(cmd, timeout=30) print(stdout.read().decode("utf-8", "replace")) err = stderr.read().decode("utf-8", "replace") if err.strip(): print("ERR", err[:800]) c.close() return if __name__ == "__main__": main()