- 论坛徽章:
- 5
|
回复 2# laike9m
def run(self):
try:
tn = telnetlib.Telnet(self.host,self.port,timeout=3)
except:
print "The %s:%s Host is Not reachable!" %(self.host,self.port)
os.sys.exit()
child = pexpect.spawn('ssh -l%s -p%s %s -q %s' %(self.user,self.port,self.host,self.cmd),timeout=3000)
index = child.expect([pexpect.EOF,pexpect.TIMEOUT,"(yes/no)","assword:","Diened"])
if index == 0:
print "the Host %s is not connected!" %(self.host)
elif index == 1:
print " To the Host %s is Timeout!" %(self.host)
elif index == 2:
child.sendline("yes")
child.expect("assword:")
child.sendline(self.password)
inner = child.expect(["LDAP",pexpect.EOF])
if inner == 0:
print "Password Error"
elif inner == 1:
print child.before
child.close()
elif index == 3:
child.sendline(self.password)
inner = child.expect(["LDAP",pexpect.EOF])
if inner == 0:
print "Password Error"
elif inner == 1:
print child.before
child.close()
print "This is %s" %(self.getName())
elif index == 4:
print "The host %s is Need LDAP Auth!" %(self.host)
elif index == 5:
print "%s is Diened!!" %(self.host) |
|