import paramiko, time, tcping, re
def main():
ip = ['10.0.0.107', '10.0.0.108', '10.0.0.109', '10.0.0.110']
for i in ip:
ping = tcping.Ping(i, 22)
ping.ping(2)
ret = ping.result.raw
results = re.findall(r"connections,(.*?)successed,",ret)
ping_result = int(results[0].strip())
if (ping_result != 0):
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=i, port=22, username="admin", password="admin", allow_agent=False, look_for_keys=False)
command = ssh_client.invoke_shell()
time.sleep(1)
command.send('screen-length 0 temporary \n')
time.sleep(1)
command.send('dis curr \n')
time.sleep(2)
output=command.recv(65535).decode('ascii')
print(output)
times = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
with open(f'd:\\{i}_{times}.txt', "w") as backup:
backup.write(output)
print(f'{i} 保存成功')
ssh_client.close()
print('-*-' * 20)
else:
print("{} is not open!!!".format(i))
if __name__ == '__main__':
main()