如何利用Python的paramiko模块实现ssh互信
1个回答
2016-02-03
展开全部
import os
import paramiko
def check(output):
# output=os.popen('service ntpd status')
for file in output:
if 'stopped' in file:
print "ntpd is stopped"
else:
print "ntpd is running"
if __name__ == 'main':
for ip in ('10.0.0.1','10.0.0.2'):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip)
# check()
stdin, stdout, stderr = ssh.exec_command("service ntpd status")
check(stdout.readlines())
ssh.close()
import paramiko
def check(output):
# output=os.popen('service ntpd status')
for file in output:
if 'stopped' in file:
print "ntpd is stopped"
else:
print "ntpd is running"
if __name__ == 'main':
for ip in ('10.0.0.1','10.0.0.2'):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip)
# check()
stdin, stdout, stderr = ssh.exec_command("service ntpd status")
check(stdout.readlines())
ssh.close()
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询