Yes, wrong module. I found the proper way to use pexpect and the if statments.
def check_creds(host, user, passwd, en_passwd):
ssh_newkey = 'Are you sure you want to continue connecting (yes/no)?'
constr = 'ssh ' + user + '@' + host
ssh = pexpect.spawn(constr)
ret = ssh.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])
if ret == 0:
print '[-] Error Connecting to ' + host
return
if ret == 1:
ssh.sendline('yes')
ret = ssh.expect([pexpect.TIMEOUT, '[P|p]assword:'])
if ret == 0:
print '[-] Could not accept new key from ' + host
return
ssh.sendline(passwd)
auth = ssh.expect(['[P|p]assword:', '>', '#'])
if auth == 0:
print 'User password is incorrect'
return
if auth == 1:
print('username and password are correct')
ssh.sendline('enable')
ssh.sendline(en_passwd)
enable = ssh.expect(['[P|p]assword:', '#'])
if enable == 0:
print 'enable password is incorrect'
return
if enable == 1:
print 'enable password is correct'
return
if auth == 2:
print 'privilege mode creds work'
return
else:
print 'creds are incorrect'
return