以下是我的代码中的代码段。出于某种原因,它根本不打印第二行说“Cracking花了10秒钟”或者其他什么,但第一位说密码发现:确实有效......为什么?
def connect(host, user, password, release):
global Found
global Fails
global startTime
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+] Password Found: ' + password
print 'Cracking the password took' + datetime.now()-startTime + 'seconds.'
Found = True
except Exception, e:
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect(host, user, password, False)
答案 0 :(得分:1)
问题可能是您没有设置startTime
,但是您通过过度广泛的异常处理来掩盖它。删除try/except
,选择一些其他异常进行陷阱,或者只是在异常处理程序中包含一个裸raise
命令,由于缺少初始化,您应该看到NameError。修复它,你的代码有更多机会。
答案 1 :(得分:1)
您正在尝试连接两个不同的内容(datetime
和str
),尝试将datetime
转换为str:
def connect(host, user, password, release):
global Found
global Fails
global startTime
try:
s = pxssh.pxssh()
s.login(host, user, password)
print '[+] Password Found: ' + password
print 'Cracking the password took' + str(datetime.now()-startTime) + 'seconds.'
Found = True
except Exception, e:
if 'read_nonblocking' in str(e):
Fails += 1
time.sleep(5)
connect(host, user, password, False)
elif 'synchronize with original prompt' in str(e):
time.sleep(1)
connect(host, user, password, False)
此外,你不应该陷入所有类型的Exception
,只是你需要的那些。